一个老个写的无组件上传

2016-01-29 20:17 8 1 收藏

一个老个写的无组件上传,一个老个写的无组件上传

【 tulaoshi.com - ASP 】

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

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/asp/)

'**Start Encode**
Action=Request("A")
If Action="UL" Then
DoUpload Request.Cookies("DAZHOU.NET")("nowpath") & ""
'CheckDiskSpace
' Response.redirect "fileman.asp"
Else
ShowUploadForm
End If

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/asp/)

Set fso=Nothing
'========================
SUB ShowUploadForm
'========================
Response.write "<Dir<form enctype=multipart/form-data name=fmupload method=Post action=Upload.asp?A=UL<br"
If Request("n")<"" AND IsNumeric(Request("n")) Then Session("NumUploadFields")=CInt(Request("n"))
For i=1 to 5
Response.Write "<INPUT type=file name=file"& i & " size=35<br"
Next
Response.Write "<br<center<INPUT type=submit value=""开始上传"" <INPUT type='button' value= '取消上传' onclick='window.close()' "
Response.Write "</form"
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 NowStartTime Then Response.Write("<br<br<br<br<center上传成功!<br速度: " & 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<PosBound) Then
'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(ch

来源:https://www.tulaoshi.com/n/20160129/1510946.html

延伸阅读
标签: ASP
  以前,如果要用ASP操作文件,比如移动、复制、删除或者创建一个记事本文件,基本上都是通过FILESYSTEMOBJECT对象做的,当然,这个东西很专业,也没说什么不好,它可以提供完善的文件信息,比如建立时间,大小,上次修改时间等等,但是如果你不做痛苦的高代价的字符格式转换的话,利用它你无法直接操作二进制文件。 但是,现在我们介绍...
标签: ASP
  出处:宝玉BLOG 一、无组件上传的原理 我还是一点一点用一个实例来说明的吧,客户端HTML如下。要浏览上传附件,我们通过<input type="file"元素,但是一定要注意必须设置form的enctype属性为"multipart/form-data": <form method="post" action="upload.asp" enctype="multipart/form-data"  <label   <inpu...
标签: ASP
  接着上回,新建一个ActiveX DLLs类型的工程,并将缺省的工程名由“Project1”改为“Songbird”(当然你也有权不这样改,呵呵),将缺省的类名由“Class1”改为“FileUp”,至于为什么要这样改,以后你便知道了。     要想实现读取上传文件字节数据的功能,势必要涉及到Request对象,可是在VB中该怎么做呢?简单,只...
标签: Web开发
New Document [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
功能很简单,就是根据传入的统计数据生成图片。 可以按照线条、圆柱、饼状进行显示。 但现在只完成了线条这一个功能。 有兴趣的朋友可以看看,如果有什么问题请和我联系。 目前主要功能: 1。线状显示数据 2。自定义图片大小 3。自定义图表标题文字的内容、字体、大小、颜色 4。X、Y轴文字内容 5。按天、月显示数据 ………...

经验教程

980

收藏

95
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部