关于ASP无组件上传文件的命名问题
我想用ASP无组件上传文件,文件名不变;比如:我上传 5.jpg上传后还是5.jpg请教怎么改
<%
dim Upload,File,FormName,SaveToPath,FileName,FileExt
dim RanNum
call UpFile()
'===========无组件上传(upload_0)====================
sub UpFile()
set Upload=new UpFile_Class '建立上传对象
Upload.GetData (1024*1024*15) '取得上传数据,此处即为15M
if Upload.err > 0 then
select case Upload.err
case 1
Response.Write "请先选择您要上传的文件,<a href=# onclick=history.go(-1)>返回</a> !"
case 2
Response.Write "文件大小超过了限制15M,<a href=# onclick=history.go(-1)>返回</a> !"
end select
exit sub
else
SaveToPath=Upload.form("SaveToPath") '文件保存目录,此目录必须为程序可读写
if SaveToPath="" then
SaveToPath="../"
end if
'在目录后加(/)
if right(SaveToPath,1)<>"/" then
SaveToPath=SaveToPath&"/"
end if
for each FormName in Upload.file '列出所有上传了的文件
set file=Upload.file(FormName) '生成一个文件对象
if file.Filesize<100 then
response.write "请先选择您要上传的文件,<a href=# onclick=history.go(-1)>返回</a> !"
response.end
end if
FileExt=lcase(File.FileExt)
if CheckFileExt(FileEXT)=false then
response.write "文件格式不允许上传,<a href=# onclick=history.go(-1)>返回</a> !"
response.end
end if
randomize timer
RanNum=int(9000*rnd)+1000
Filename=SaveToPath&request("FileName")&fileExt
if file.FileSize>0 then '如果 FileSize > 0 说明有文件数据
Result=file.SaveToFile(Server.mappath(FileName)) '保存文件
if Result="ok" then
response.write "<table width='100%' border='0' cellspacing='0' cellpadding='0'>"
response.write "<tr>"
response.write "<td width='60' height='30'>上传成功:</td>"
response.write "<td nowrap><font color='#ff0000'>"&File.FilePath&file.FileName&"</font></td>"
response.write "</tr>"
response.write "<tr>"
response.write "<td nowrap height='30'>保存路径:</td>"
response.write "<td nowrap><input type='text' size='56' class='textfield' value='"&right(FileName,len(FileName))&"'></td>"
response.write "</tr>"
response.write "<tr>"
response.write "<td nowrap height='30'>文件大小:</td>"
response.write "<td nowrap><input type='text' size='56' class='textfield' value='"&GainFileSize(file.Filesize)&"'></td>"
response.write "</tr>"
response.write "<tr>"
response.write "<td height='36' colspan='2' valign='bottom' align='center'><input name='CopyPath' type='button' class='button' value='拷贝文件路径' onclick=""CopyPath('"&right(FileName,len(FileName))&"','"&GainFileSize(file.Filesize)&"')""></td>"
response.write "</tr>"
response.write "</table>"
else
response.write File.FilePath&file.FileName&"上传失败 !"&Result&"<br>"
end if
end if
set file=nothing
next
set Upload=nothing
end if
end sub
'判断文件类型是否合格
Private Function CheckFileExt (FileEXT)
dim ForumUpload
ForumUpload="exe,gif,jpg,jpeg,rar,zip,doc"
ForumUpload=split(ForumUpload,",")
for i=0 to ubound(ForumUpload)
if lcase(FileEXT)=lcase(trim(ForumUpload(i))) then
CheckFileExt=true
exit Function
else
CheckFileExt=false
end if
next
End Function
Private Function GainFileSize (SizeByte)
if SizeByte < 1024*1024 then
GainFileSize=round(SizeByte/1024,2) & " KB"
else
GainFileSize=round(SizeByte/1024/1024,2) & " MB"
end if
End Function
%>