-
您的位置:首页 → 网页设计 → ASP实例 → 一个的无组件上传的ASP代码
一个的无组件上传的ASP代码
时间:2004/11/7 3:00:00来源:本站整理作者:蓝点我要评论(0)
-
<%
Response.write "上传文件至当前文件夹"
Response.Write ""
'**Start Encode**
Action=Request("A")
If Action="UL" Then
DoUpload Request.Cookies("DAZHOU.NET")("nowpath") & "\"
'CheckDiskSpace
' Response.redirect "fileman.asp"
Else
ShowUploadForm
End If
Set fso=Nothing
'========================
SUB ShowUploadForm
'========================
Response.write ""
End SUB
'========================
SUB DoUpload(Dir)
'========================
'If NOT Application("Debugging") Then On Error resume next
StartTime=Now
RequestBin=Request.BinaryRead(Request.TotalBytes)
Set UploadRequest=CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin, UploadRequest
keys=UploadRequest.Keys
For i=0 to UploadRequest.Count - 1
curKey=keys(i)
fName=UploadRequest.Item(curKey).Item("FileName")
If fso.FileExists(Dir & fName) Then fso.deletefile Dir & fName
If fName<>"" AND NOT fso.FileExists(Dir & fName) Then
value=UploadRequest.Item(curKey).Item("Value")
valueBeg=UploadRequest.Item(curKey).Item("ValueBeg")
valueLen=UploadRequest.Item(curKey).Item("ValueLen")
TotalULSize=TotalULSize + valueLen
Set strm1=Server.CreateObject("ADODB.Stream")
Set strm2=Server.CreateObject("ADODB.Stream")
strm1.Open
strm1.Type=1 'Binary
strm2.Open
strm2.Type=1 'Binary
strm1.Write RequestBin
strm1.Position=ValueBeg
strm1.CopyTo strm2,ValueLen
strm2.SaveToFile Dir & fName,2
Set strm1=Nothing
Set strm2=Nothing
End If
Next
If Now>StartTime Then Response.Write("
上传成功!
速度: " & Round(TotalULSize/1024/DateDiff("s",StartTime,Now)) &" 千字节/秒" )
Set UploadRequest=Nothing
End SUB
'========================
Sub BuildUploadRequest(RequestBin, UploadRequest)
'========================
'Get the boundary
PosBeg=1
PosEnd=InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary=MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos=InstrB(1,RequestBin,boundary)
'Get all data inside the boundaries
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
'Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl=CreateObject("Scripting.Dictionary")
'Get an object name
Pos=InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos=InstrB(Pos,RequestBin,getByteString("name="))
PosBeg=Pos+6
PosEnd=InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name=getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile=InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound=InstrB(PosEnd,RequestBin,boundary)
'Test if object is of file type
If PosFile<>0 AND (PosFile
'Get Filename, content-type and content of file
PosBeg=PosFile + 10
PosEnd=InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName=getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
FileName=Mid(FileName,InStrRev(FileName,"\")+1)
'Add filename to dictionary object
UploadControl.Add "FileName", FileName
Pos=InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg=Pos+14
PosEnd=InstrB(PosBeg,RequestBin,getByteString(chr(13)))
'Add content-type to dictionary object
ContentType=getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
'Get content of object
PosBeg=PosEnd+4
PosEnd=InstrB(PosBeg,RequestBin,boundary)-2
Value=FileName
ValueBeg=PosBeg-1
ValueLen=PosEnd-Posbeg
Else
'Get content of object
Pos=InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg=Pos+4
PosEnd=InstrB(PosBeg,RequestBin,boundary)-2
Value=getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
ValueBeg=0
ValueEnd=0
End If
UploadControl.Add "Value" , Value
UploadControl.Add "ValueBeg" , ValueBeg
UploadControl.Add "ValueLen" , ValueLen
UploadRequest.Add name, UploadControl
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
End Sub
'====================================
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
%>
相关阅读
Mac和Windows哪个好 windows和mac os对比介绍Win10预览版怎么升级 Win10预览版升级方法厂商不再预装Win7或8.1系统,驱动人生帮您快速升级Mac移动硬盘安装win8 Mac将win装在移动硬盘使用教程windows10xboxone串流简单教程Windows Hello怎么用 Windows Hello使用设置教程win10怎么关闭自动更新 win10如何关闭自动更新Mac系统如何远程桌面到Windows系统
-
热门文章
没有查询到任何记录。
最新文章
迅雷新手完全入门手册
asp下面javascript上传图片限制格式大小方法告诉大家网页弹出窗口应用总结ASP常见错误类型大全asp常见错误分析和解决办法
人气排行
总是弹出visual studio 实时调试器 三种解决SQLSERVER存储过程及调用详解Asp获取真实IP地址ASP中连接Mssql的几种方法一个简单好用的UBB编辑器(含代码)如何用Split将字符串转换为数组并获取数组下ASP防止表单重复提交的办法告诉你免费的简单聊天室源代码
支持( 0 ) 盖楼(回复)
查看所有0条评论>>