一个老个写的无组件上传

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

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

【 tulaoshi.com - ASP 】

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

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

(本文来源于图老师网站,更多请访问http://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

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

'========================
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

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

延伸阅读
标签: ASP
  出处:宝玉BLOG 一、无组件上传的原理 我还是一点一点用一个实例来说明的吧,客户端HTML如下。要浏览上传附件,我们通过<input type="file"元素,但是一定要注意必须设置form的enctype属性为"multipart/form-data": <form method="post" action="upload.asp" enctype="multipart/form-data"  <label   <inpu...
标签: ASP
  最近在单位做的一个项目里需要有文件上传的功能,正好手头一本书的附赠光盘里有一个上传组件,心中大喜。可惜随之便发现这是一个试用版,不给钱就只能用50次,太小气了!!好在头头催得不紧,时间充裕,干脆自己试着做一个,既可长经验值,又能长成就感,不试白不试!以下介绍的便是俺折腾了两天半捣鼓出来的一个只能说是雏形的玩意,区...
标签: ASP
  接着上回,新建一个ActiveX DLLs类型的工程,并将缺省的工程名由“Project1”改为“Songbird”(当然你也有权不这样改,呵呵),将缺省的类名由“Class1”改为“FileUp”,至于为什么要这样改,以后你便知道了。     要想实现读取上传文件字节数据的功能,势必要涉及到Request对象,可是在VB中该怎么做呢?简单,只...
标签: Web开发
New Document [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
功能很简单,就是根据传入的统计数据生成图片。 可以按照线条、圆柱、饼状进行显示。 但现在只完成了线条这一个功能。 有兴趣的朋友可以看看,如果有什么问题请和我联系。 目前主要功能: 1。线状显示数据 2。自定义图片大小 3。自定义图表标题文字的内容、字体、大小、颜色 4。X、Y轴文字内容 5。按天、月显示数据 ………...

经验教程

178

收藏

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