But perhaps with the gradual fading out of the web development of the ASP, the official only provided the version of. NET, PHP upload processing program, for the ASP developers need to handle server-side data reception.
It's powerful and flexible and easy to attract when you just touch this component, as a result of the project using ASP development, Baidu after some found that there is no easy to use ASP upload processing program (now have a lot of ^ ^), it seems only their own research and development, the original use of processing ordinary upload method to intercept the file data, After testing found that the component can not be effectively received by the file data, but can only start analysis of the data it sent to the form, through analysis found that it sent the data format or ordinary upload there are some differences, whether it is a picture or file are sent to the server in Octet-stream form, Understand the data format, the rest is to intercept, the following my processing methods to share to the needs of friends, processing speed is ideal.
Copy Code code as follows:
<%
Class SWFUpload
Private FormData, FolderPath, Streamget
Private fileSize, chunksize, Bofcont, Eofcont
REM class-initialize
Private Sub Class_Initialize
Call Initvariant
Server.ScriptTimeout = 1800
Set streamget = Server.CreateObject ("ADODB. Stream ")
Sauthor = "51JS.COM-ZMM"
Sversion = "Upload Class 1.0"
End Sub
REM class-initialize
Public Property Let Savefolder (ByVal sfolder)
If Right (sfolder, 1) = "/" Then
FolderPath = Sfolder
Else
FolderPath = Sfolder & "/"
End If
End Property
Public Property Get Savefolder
Savefolder = FolderPath
End Property
Private Function Initvariant
chunksize = 1024 * 128
FolderPath = "/": fileSize = 1024 * 10
Bofcont = Strtobyte ("Octet-stream" & VbCrlf & VbCrlf)
Eofcont = Strtobyte (VbCrlf & String (12, "-"))
End Function
Public Function Getuploaddata
Dim curread:curread = 0
Dim Datalen:datalen = request.totalbytes
Streamget.type = 1:streamget.open
Do While Curread < Datalen
Dim Partlen:partlen = chunksize
If Partlen + curread > datalen Then partlen = Datalen-curread
Streamget.write Request.BinaryRead (Partlen)
Curread = Curread + Partlen
Loop
streamget.position = 0
FormData = Streamget.read (datalen)
Call Getuploadfile
End Function
Public Function Getuploadfile
Dim Begmark:begmark = Strtobyte ("Filename=")
Dim Begpath:begpath = InStrB (1, FormData, Begmark & ChrB (34)) + 10
Dim Endpath:endpath = InStrB (Begpath, FormData, ChrB (34))
Dim Cntpath:cntpath = MidB (FormData, Begpath, Endpath-begpath)
Dim cntname:cntname = folderpath & Getclientname (Cntpath)
Dim begfile:begfile = InStrB (1, FormData, Bofcont) + 15
Dim endfile:endfile = InStrB (Begfile, FormData, Eofcont)
Call Saveuploadfile (Cntname, Begfile, Endfile-begfile)
End Function
Public Function saveuploadfile (ByVal fName, ByVal Bcont, ByVal slen)
Dim Filepath:filepath = Server.MapPath (fName)
If CreateFolder ("|", Getparentfolder (FilePath)) Then
Streamget.position = Bcont
Set streamput = Server.CreateObject ("ADODB. Stream ")
Streamput.type = 1:streamput.mode = 3:streamput.open
Streamput.write Streamget.read (Slen)
Streamput.savetofile FilePath, 2
StreamPut.Close:Set Streamput = Nothing
End If
End Function
Private Function isnothing (ByVal sVar)
IsNothing = IsNull (SVar) Or (SVar = Empty)
End Function
Private Function strtobyte (ByVal stext)
For i = 1 to Len (stext)
Strtobyte = strtobyte & ChrB (ASC (Mid (Stext, I, 1))
Next
End Function
Private Function bytetostr (ByVal sByte)
Dim streamtmp
Set streamtmp = Server.CreateObject ("ADODB. Stream ")
Streamtmp.type = 2
Streamtmp.mode = 3
Streamtmp.open
Streamtmp.writetext SByte
streamtmp.position = 0
Streamtmp.charset = "Utf-8"
Streamtmp.position = 2
Bytetostr = Streamtmp.readtext
Streamtmp.close
Set streamtmp = Nothing
End Function
Private Function getclientname (byVal binfo)
Dim Sinfo, RegEx
Sinfo = Bytetostr (binfo)
If isnothing (sinfo) Then
Getclientname = ""
Else
Set regEx = New RegExp
Regex.pattern = "^.*\\ ([^\\]+) $"
Regex.global = False
Regex.ignorecase = True
Getclientname = Regex.Replace (Sinfo, "$")
Set regEx = Nothing
End If
End Function
Private Function Getparentfolder (ByVal spath)
Dim regEx
Set regEx = New RegExp
Regex.pattern = "^ (. *) \\[^\\]*$"
Regex.global = True
Regex.ignorecase = True
Getparentfolder = Regex.Replace (spath, "$")
Set regEx = Nothing
End Function
Private Function CreateFolder (ByVal sline, ByVal spath)
Dim oFSO
Set oFSO = Server.CreateObject ("Scripting.FileSystemObject")
If not ofso.folderexists (spath) Then
Dim regEx
Set regEx = New RegExp
Regex.pattern = "^ (. *) \ ([^\\]*) $"
Regex.global = False
Regex.ignorecase = True
sline = sline & Regex.Replace (spath, "$") & "|"
spath = Regex.Replace (spath, "$")
If CreateFolder (sline, spath) Then CreateFolder = True
Set regEx = Nothing
Else
If sline = "|" Then
CreateFolder = True
Else
Dim stemp:stemp = Mid (sline, 2, Len (sline)-2)
If InStrRev (stemp, "|") = 0 Then
sline = "|"
spath = spath & "\" & Stemp
Else
Dim Folder:folder = Mid (Stemp, InStrRev (stemp, "|") + 1)
sline = "|" & Mid (Stemp, 1, InStrRev (stemp, "|")-1) & "|"
spath = spath & "\" & Folder
End If
Ofso.createfolder spath
If CreateFolder (sline, spath) Then CreateFolder = True
End If
End If
Set oFSO = Nothing
End Function
REM class-terminate
Private Sub Class_Terminate
Streamget.close
Set Streamget = Nothing
End Sub
End Class
REM Call method
Dim Oupload
Set oupload = New swfupload
Oupload.savefolder = "Store Path"
Oupload.getuploaddata
Set oupload = Nothing
%>