上传附件
上传附件时文件名为什么不是附件的名称,而是随机生成的数字。在网上找的代码,刚接触asp,菜鸟一个,帮看看在哪里改代码
<!--#include file="Conn.asp"-->
<!--#include file="Function.asp"-->
<!--#include file="upfile_class.asp"-->
<%Server.ScriptTimeOut=999999999%>
<style type="text/css">
body{
margin:0px;
font-family:"verdana";
font-size:12px;
}
table,td{font-family:"verdana";
font-size:12px;}
A:link,A:active,A:visited
{TEXT-DECORATION:none ;Color:#000000
}
INPUT {
BORDER-TOP-WIDTH: 1px; BORDER-LEFT-WIDTH: 1px; FONT-SIZE: 12px; BORDER-BOTTOM-WIDTH: 1px; BORDER-RIGHT-WIDTH: 1px
}
</style>
<%
if Session("UserName")="" Then
response.write "您还没有登陆!"
response.End
end if
dim action
dim mySavePath,myformName
Dim upfilemaxsize,upfileallType
'重新设置
dim GroupInfo
GroupInfo=GetGroupInfo(Session("GroupID"))
upfilemaxsize=clng(GroupInfo(2)) '限制文件大小 KB
upfileallType=GroupInfo(1) '允许上传类型
action=trim(request("action"))
mySavePath=Request.QueryString("SavePath")
myformName=Request.QueryString("formName")
select case action
case "add"
add
case "save"
save
case else
add
end select
sub add
%>
<SCRIPT language=javascript>
function check()
{
var strFileName=document.form1.FileName.value;
if (strFileName=="")
{
alert("请选择要上传的文件。");
document.form1.FileName.focus();
return false;
}
}
</SCRIPT>
<table>
<form action="?action=save&formName=<%=myformName%>&SavePath=<%=mySavePath%>" method="post" name="form1" onSubmit="return check()" enctype="multipart/form-data">
<tr><td>文件上传:<input name="FileName" type="file" id="FileName" size="40" >
<input type="submit" value="上传" name="submit" ><!-- <font color="#FF0000"><%=CStr(upfilemaxsize)%>K</font>内-->
</form>
</td></tr>
</table>
<%
end sub
sub save
if GroupInfo(1)="" or GroupInfo(2)="" then
Response.Write("<script language=JavaScript>alert('您不允许上传文件,需要上传请与管理员联系!');document.location.href='javascript:window.history.go(-1);';</script>")
Response.End
End If
call upload_0() '使用无组件上传类
end sub
sub upload_0() '使用无组件上传类
dim upload,oFile,formName,SavePath,filename,fileExt,oFileSize
dim i,myfileName
dim msg,FoundErr
msg=""
FoundErr=false
set upload=new upfile_class ''建立上传对象
upload.GetData(104857600) '取得上传数据,限制最大上传100M
if upload.err > 0 then '如果出错
select case upload.err
case 1
response.write "请先选择你要上传的文件!"
case 2
response.write "你上传的文件总大小超出了最大限制(100M)"
end select
response.end
end if
SavePath ="UploadFile/" '存放上传文件的目录
if right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)
'SavePath=CreatePath(SavePath)
if right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)
for each formName in upload.file '列出所有上传了的文件
set ofile=upload.file(formName) '生成一个文件对象
oFileSize=ofile.filesize
if oFileSize<100 then
msg="请先选择你要上传的文件!"
FoundErr=True
elseif oFileSize>(upfilemaxsize*1024*1024) then
msg="文件大小超过了限制,最大只能上传" & CStr(upfilemaxsize) & "MB的文件!"
FoundErr=true
end if
fileExt=lcase(ofile.FileExt)
If CheckFileExt(fileExt) = False then
msg="上传失败!只允许上传这几种文件类型:" & replace(upfileallType,"|",",")
FoundErr=true
end if
if FoundErr<>true then
filename=FormatName(fileExt)
myfileName=filename
filename=SavePath&filename
ofile.SaveToFile Server.mappath(FileName) '保存文件
Session("filesize")=Session("filesize")+oFileSize
response.write "文件上传成功!文件大小为:" &FormatFileSize(oFileSize)&""
response.write" <a href='?action=add&formName="&myformName&"&SavePath="&mySavePath&"'><font color=red>继续上传</font></a>"
Response.Write "<script>parent.AddItem('" &myfileName& "');</script>"
else
response.write("<font color=red>" & msg & "</font> <b><a href='javascript:history.back()'><font color=blue>返回<font></a></b>")
end if
set ofile=nothing
next
set upload=nothing
end sub
Function CheckFileExt(FileExt)
Dim Forumupload,i
CheckFileExt=False
If FileExt="" or IsEmpty(FileExt) Then
CheckFileExt = False
Exit Function
End If
If FileExt="asp" or FileExt="asa" or FileExt="aspx" or FileExt="cer" or FileExt="cdx" then
CheckFileExt = False
Exit Function
End If
Forumupload = Split(LCase(upfileallType),"|")
For i = 0 To ubound(Forumupload)
If FileExt = Trim(Forumupload(i)) Then
CheckFileExt = True
Exit Function
Else
CheckFileExt = False
End If
Next
End Function
Function FormatName(Byval FileExt)
Dim RanNum,TempStr
Randomize
RanNum = Int(90000*rnd)+10000
TempStr = Year(now) & Month(now) & Day(now) & Hour(now) & Minute(now) & Second(now) & RanNum & "." & FileExt
FormatName = TempStr
End Function
function FormatFileSize(xxx)
dim show11
show11=xxx & " Byte"
if xxx>=1024 then
xxx=(xxx/1024)
show11=round(xxx,2) & " KB"
end if
if xxx>=1024 then
xxx=(xxx/1024)
show11=round(xxx,2) & " MB"
end if
FormatFileSize=cstr(show11)
end function
Function CreatePath(PathValue)
Dim objFSO,Fsofolder,uploadpath
uploadpath = Year(Date) & "-" & Month(Date)
If Right(PathValue,1)<>"/" Then PathValue = PathValue&"/"
On Error Resume Next
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(Server.MapPath(PathValue & uploadpath))=False Then
objFSO.CreateFolder Server.MapPath(PathValue & uploadpath)
End If
If Err.Number = 0 Then
CreatePath = PathValue & uploadpath & "/"
Else
CreatePath = PathValue
End If
Set objFSO = Nothing
End Function
%>
[ 本帖最后由 ljjlxj 于 2013-3-28 08:49 编辑 ]