📄 upfile.asp
字号:
<!--#include file="Inc/upfile_class.asp"-->
<html>
<head>
<title>文件上传</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body topmargin="0" leftmargin="0" background="#E7F7EF">
<table width=100% border=0 cellspacing="0" cellpadding="0" bgcolor=#FFFFFF>
<tr><td width=100% height=100% >
<%
server.scripttimeout=3000 '指定更长时间,以防网速过慢造成服务器脚本超时!
dim fpath,EnableUpload
dim upload,file,formName,formPath,iCount,filename,fileExt
dim ranNum
call upload_0()
'===========无组件上传(upload_0)====================
sub upload_0()
set upload=new UpFile_Class ''建立上传对象
upload.GetDate (10*1024*1024) '取得上传数据,是大数10M
iCount=0
fpath=trim(upload.form("fpath"))
if upload.err > 0 then
select case upload.err
case 1
response.write "<font color=red><br>请先选择您要上传的文件!</font> [<a href=upload.asp?fpath="&fpath&">重新上传</a>]"
case 2
response.write "<font color=red><br>文件大小超过了限制 10M!</font> [<a href=upload.asp?fpath="&fpath&">重新上传</a>]"
end select
exit sub
else
formPath=fpath '存放上传文件的目录
if right(formPath,1)<>"/" then formPath=formPath&"/" '在目录后加(/)
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
if file.filesize<100 then
response.write "<font color=red><br>请先选择您要上传的文件!</font> [<a href=upload.asp?fpath="&fpath&">重新上传</a>]"
response.end
end if
fileExt=lcase(file.FileExt)
if CheckFileExt(fileEXT)=false then
response.write "<font color=red><br>文件格式不正确!</font> [<a href=upload.asp?fpath="&fpath&">重新上传</a>]"
response.end
end if
randomize
ranNum=int(90000*rnd)+10000
filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
if file.FileSize>0 then '如果 FileSize > 0 说明有文件数据
file.SaveToFile Server.mappath(filename) '保存文件
if fpath="smallpic" then
response.write "<script language=javascript>parent.document.forms[0].picurl.value='"&filename&"';</script>"
else
response.write "<script language=javascript>parent.document.forms[0].url.value='"&filename&"';</script>"
end if
iCount=iCount+1
end if
set file=nothing
next
set upload=nothing
Htmend iCount&"个文件上传结束!"
end if
end sub
sub HtmEnd(Msg)
response.write "<font color=red><br>文件上传成功!</font> [<a href=upload.asp?fpath="&fpath&">重新上传</a>]"
response.end
end sub
'判断文件类型是否合格
Private Function CheckFileExt (fileEXT)
dim Forumupload,i
if fpath="upload" then '上传swf
Forumupload="swf|fla"
else
Forumupload="jpeg|bmp|png|gif|jpg" '允放上传的文件格式
end if
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
%>
</td></tr></table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -