专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Asp教程 » asp无组件上传:无组件上传 »正文

asp无组件上传:无组件上传

来源: 发布时间:星期四, 2009年2月12日 浏览:1709次 评论:0


<!--#file=\"../lib/filelib.asp\"-->
<%
Response.write\"<title>上传文件至当前文件夹</title>\"
Response.Write\"<bodybgcolor=\"\"#D6D3CE\"\"leftmargin=\"\"0\"\"topmargin=\"\"0\"\"title=\"\"请您遵守国家相关法律法规上传文件上传前请杀毒否则系统将会自动删除此文件!\"\">\"

\'**StartEncode**
Action=Request(\"A\")
IfAction=\"UL\"Then
DoUploadRequest.Cookies(\"DAZHOU.NET\")(\"nowpath\")&\"\\\"
\'CheckDiskSpace
\'Response.redirect\"fileman.asp\"
Else
ShowUploadForm
EndIf

Setfso=Nothing
\'
SUBShowUploadForm
\'
Response.write\"<Dir><formenctype=multipart/form-dataname=fmuploadmethod=Postaction=Upload.asp?A=UL><br>\"
IfRequest(\"n\")<>\"\"ANDIsNumeric(Request(\"n\"))ThenSession(\"NumUploadFields\")=CInt(Request(\"n\"))
Fori=1to5
Response.Write\"<INPUTtype=filename=file\"&i&\"size=35><br>\"
Next
Response.Write\"<br><center><INPUTtype=submitvalue=\"\"开始上传\"\"><INPUTtype=\'button\'value=\'取消上传\'onclick=\'window.close\'>\"
Response.Write\"</form>\"
EndSUB

\'
SUBDoUpload(Dir)
\'
\'IfNOTApplication(\"Debugging\")ThenOnErrorresumenext
StartTime=Now
RequestBin=Request.BinaryRead(Request.TotalBytes)
SetUploadRequest=CreateObject(\"Scripting.Dictionary\")
BuildUploadRequestRequestBin,UploadRequest
keys=UploadRequest.Keys
Fori=0toUploadRequest.Count-1
curKey=keys(i)
fName=UploadRequest.Item(curKey).Item(\"FileName\")

Iffso.FileExists(Dir&fName)Thenfso.deletefileDir&fName
IffName<>\"\"ANDNOTfso.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
Setstrm1=Server.CreateObject(\"ADODB.Stream\")
Setstrm2=Server.CreateObject(\"ADODB.Stream\")
strm1.Open
strm1.Type=1\'Binary
strm2.Open
strm2.Type=1\'Binary
strm1.WriteRequestBin
strm1.Position=valueBeg
strm1.CopyTostrm2,valueLen
strm2.SaveToFileDir&fName,2
Setstrm1=Nothing
Setstrm2=Nothing
EndIf
Next
IfNow>StartTimeThenResponse.Write(\"<br><br><br><br><center>上传成功!<br>速度:\"&Round(TotalULSize/1024/DateDf(\"s\",StartTime,Now))&\"千字节/秒\")
SetUploadRequest=Nothing
EndSUB

\'
SubBuildUploadRequest(RequestBin,UploadRequest)
\'
\'Gettheboundary
PosBeg=1
PosEnd=InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary=MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos=InstrB(1,RequestBin,boundary)
\'Getalldatainsidetheboundaries
Dountil(boundaryPos=InstrB(RequestBin,boundary&getByteString(\"--\")))
\'Membersvariableofobjectsareputinadictionaryobject
DimUploadControl
SetUploadControl=CreateObject(\"Scripting.Dictionary\")
\'Getanobjectname
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)
\'Testobjectisoffiletype
IfPosFile<>0AND(PosFile<PosBound)Then
\'GetFilename,content-typeandcontentoffile
PosBeg=PosFile+10
PosEnd=InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName=getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
FileName=Mid(FileName,InStrRev(FileName,\"\\\")+1)
\'Addfilenametodictionaryobject
UploadControl.Add\"FileName\",FileName
Pos=InstrB(PosEnd,RequestBin,getByteString(\"Content-Type:\"))
PosBeg=Pos+14
PosEnd=InstrB(PosBeg,RequestBin,getByteString(chr(13)))
\'Addcontent-typetodictionaryobject
ContentType=getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))


UploadControl.Add\"ContentType\",ContentType
\'Getcontentofobject
PosBeg=PosEnd+4
PosEnd=InstrB(PosBeg,RequestBin,boundary)-2
value=FileName
valueBeg=PosBeg-1
valueLen=PosEnd-Posbeg
Else
\'Getcontentofobject
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
EndIf
UploadControl.Add\"value\",value
UploadControl.Add\"valueBeg\",valueBeg
UploadControl.Add\"valueLen\",valueLen
UploadRequest.Addname,UploadControl
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
EndSub

\'
FunctiongetByteString(StringStr)
\'
Fori=1toLen(StringStr)
char=Mid(StringStr,i,1)
getByteString=getByteString&chrB(AscB(char))
Next
EndFunction

\'
FunctiongetString(StringBin)
\'
getString=\"\"
ForCount=1toLenB(StringBin)
getString=getString&chr(AscB(MidB(StringBin,Count,1)))
Next
EndFunction
%>

7

相关文章

读者评论

  • 1sdf(203.156.193.*) 发布于:星期日, 2008年12月7日
    sdfsdfs

发表评论

  • 昵称:
  • 内容: