用<input type=file>实现文件上传
发表于:2007-06-30来源:作者:点击数:
标签:
资料来源精华区 稻草老农等人 submit.htm htmltitleexample/title body form name=form1 method=post action=upload.asp enctype=multipart/form-data input type=file name=file1 input type=submit name=submit value=提交 /form /body /html upload.asp %@
资料来源精华区 稻草老农等人
submit.htm
<html><title>example</title>
<body>
<form name="form1" method="post" action="upload.asp" enctype="multipart/form-data">
<input type=file name="file1">
<input type=submit name="submit" value="提交">
</form>
</body>
</html>
upload.asp
<%@ Language=
VBScript %>
<%
function binarytoasi(byval varstr)
asi=""
for i=1 to 3
asi=asi&chr(ascb(midb(varstr,i,1)))
next
binarytoasi=asi
end function
formsize=request.totalbytes
formdata=request.binaryread(request.totalbytes ) ‘’获得上传数据
bcrlf=chrB(13) & chrB(10)
divider=leftB(formdata,clng(instrb(formdata,bcrlf))-1)
Position=instrb(formdata,bcrlf & bcrlf)+4 ‘’上传文件数据开始位
filesize=instrb(Position+1,formdata,divider)-Position-4 ‘’上传文件数据长度
exnamestart=instrb(1,formdata,chrb(46),1)+1
exnameend=instrb(exnamestart,formdata,chrb(34),1)
exname=midb(formdata,exnamestart,exnameend-exnamestart)
set dr=CreateObject("Adodb.Stream")
dr.Mode=3: dr.Type=1:dr.Open
set dr1=CreateObject("Adodb.Stream")
dr1.Mode=3:dr1.Type=1:dr1.Open
dr.Write formdata
dr.Position=Position-1
dr.CopyTo dr1,filesize
dr1.SaveToFile "d:/mailtemp/temp_"&session("userid")&"."&binarytoasi(exname),2 ‘’文件保存
set dr=nothing:set dr1=nothing
%>
原文转自:http://www.ltesting.net