用<input type=file>实现文件上传
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
%>
Tags:
作者:佚名评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论