⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 up.asp

📁 较完善的一个程序
💻 ASP
字号:
<%
 dim siteurl,picsavefolder,limitbyte,lsfilename
 picsavefolder = "uppic/"   '图片保存文件夹(以"/"符号结尾)
 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="up.asp" enctype="multipart/form-data">
    这是一个实现文件上传的例子:<br>
    请选择文件:
 <INPUT TYPE="file" NAME="file">
 <INPUT TYPE="submit" value="上传">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;大小限制:<%=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=".swf" 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>复制下面红色的文件名到图片提交栏,<br>文件名  <font color=red>"&picsavefolder&filename&"</font>"
 
 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 + -