📄 aspupload.asp
字号:
<%
dim siteurl,picsavefolder,limitbyte,lsfilename
siteurl = "http://localhost/hj" '网站地址(末尾不要有"/"符号)
picsavefolder = "uploadfile/" '图片保存文件夹(以"/"符号结尾)
limitbyte = 300 '文件大小限制,单位:k
if request.totalbytes < 192 then
%>
<html>
<head>
<title>文件上传</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>
<body>
<form name="form2" method=post action="upload.asp" enctype="multipart/form-data">
请选择文件:
<input type="file" name="file">
<input type="submit" value="上传"> 大小限制:<%=limitbyte%>k
</form>
</body>
</html>
<%
else
dim contentlen
'接收表单信息
contentlen=request.totalbytes
'检测文件大小
if contentlen>limitbyte*1024 then
response.write "文件超过"&limitbyte&"k,不允许上传!"
else
dim content
'读取上传文件信息
content=request.binaryread(request.totalbytes)
'二进制相互转换函数
function getbytestring(stringstr)
for i=1 to len(stringstr)
char=mid(stringstr,i,1)
getbytestring=getbytestring&chrb(ascb(char))
next
end function
function getstring(stringbin)
getstring =""
for intcount = 1 to lenb(stringbin)
getstring = getstring & chr(ascb(midb(stringbin,intcount,1)))
next
end function
'处理数据
dim upbeg,upend,lineone,linetwo,linethree,line1,line2,line3
upbeg=1
upend=instrb(upbeg,content,getbytestring(chr(10)))
lineone=midb(content,upbeg,upend-upbeg)
upbeg=upend+1
line1=lenb(lineone)
upend=instrb(upbeg,content,getbytestring(chr(10)))
linetwo=midb(content,upbeg,upend-upbeg)
upbeg=upend+1
line2=lenb(linetwo)
upend=instrb(upbeg,content,getbytestring(chr(13)))
linethree=midb(content,upbeg,upend-upbeg)
line3=lenb(linethree)
'获得文件名
dim pp,checknametemp,checklen,checkname,filename
pp=instrb(1,linetwo,getbytestring(chr(46)))
checknametemp=rightb(linetwo,line2-pp+1)
checklen=instrb(1,checknametemp,getbytestring(chr(34)))
checkname=getstring(leftb(checknametemp,checklen-1))
'检测文件后缀
if checkname<>"content-disposition: form-data; name=" then
if checkname=".txt" or checkname=".doc" or checkname=".gif" or checkname=".jpg" or checkname=".jpeg" or checkname=".zip" or checkname=".rar" or checkname=".bmp" or checkname=".png" or checkname=".tiff" then
'定义文件名
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&checkname
'上传文件
dim alllen,upstream,upstreamend,file
alllen=line1+line2+line3+6
set upstream=server.createobject("adodb.stream")
set upstreamend=server.createobject("adodb.stream")
upstream.type=1
upstreamend.type=1
upstream.open
upstreamend.open
upstream.write content
upstream.position=alllen
file=upstream.read(clng(contentlen-alllen-line1-5))
upstreamend.write file
upstreamend.savetofile(server.mappath(picsavefolder&filename))
upstream.close
upstreamend.close
set upstream=nothing
set upstreamend=nothing
response.write "文件上传成功!<br>文件名:"&siteurl&"/"&picsavefolder&filename
else
response.write "不允许上传"&checkname&"格式文件"
end if
else
response.write "您没有填写文件名"
end if
end if
end if
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -