无组件上传实例

80酷酷网    80kuku.com

  上传|无组件

这是我从我以前写过的程序中分离出来的,由于这段代码是针对整体成体程序写的,因此功能非常简单,而且对于上传的数据也没有严格的限制,所以难免会出现这样或那样的错误。

我贴着篇文章主要是让大家了解一下无组件上传的思路,而不是让大家使用的。

<%

'Yanhang.00上传程序V1.0
'1.0版本的程序是从以前的程序修改过来的,但是可能还是仍有不足,如果你发现任何错误,请写信通知我,谢谢!
'请在使用前先修改下面的信息
'目前本程序我认为最大的不足就是只能用系统时间定义文件名,不能使用源文件名,这一点我会在以后的版本中改进。
'Enjoy yourself!

'程序制作:yanhang
'email:yanhangmsn.com
'技术支持:
'本程序要运行在ado 2.5以上版本环境下

'#####################请修改以下信息#####################################
 dim siteurl,picsavefolder,limitbyte,lsfilename
 siteurl = ""  '网站地址(末尾不要有"/"符号)
 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 "文件上传成功!
文件名:"&siteurl&"/"&picsavefolder&filename
 
 else
 response.write "不允许上传"&checkname&"格式文件"
 end if

 else
 response.write "您没有填写文件名"
 end if
 
 end if
end if
%>

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: