The SWFUpload upload component was originally developed by Vinterwebb.se. The main body of the component is integrated with Flash and JavaScript. It is mainly dedicated to solving the problem of uploading multiple files and large files. The component provides a wealth of events and interfaces for easy calling by web developers. You can easily control the style and achieve the desired upload effect through js and css. But perhaps as ASP gradually fades out of web development, the official only provides upload processing programs for .net, php and other versions. For ASP developers, they need to handle the data reception on the server side by themselves.
When I first came into contact with this component, I was attracted by its powerful functions, flexibility and convenience. Since the project was developed using ASP at that time, Baidu found out after some research that there was no useful ASP upload processing program (now there are many^^), so it seemed that I could only do it myself. Research and development. Initially, the method of processing ordinary uploads was used to intercept file data. After several tests, it was found that it could not effectively receive the file data passed by the component. , I had no choice but to start analyzing the data format it sent. Through analysis, I found that the data format it sent was still somewhat different from ordinary uploads. Both pictures and files were sent to the server in octet-stream form. I understood the data. Formatting, the rest is to intercept. I will share my processing method with friends who need it. The processing speed is quite ideal.
Copy the code code as follows:
<%
Class SWUpload
Private formData, folderPath, streamGet
Private fileSize, chunkSize, bofCont, eofCont
REM CLASS-INITIALIZE
Private Sub Class_Initialize
CallInitVariant
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, $1)
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, $1)
Set regEx = Nothing
End Function
Private Function CreateFolder(byVal sLine, byVal sPath)
fO
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, $2) & |
sPath = regEx.Replace(sPath, $1)
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 = storage path
oUpload.GetUploadData
Set oUpload = Nothing
%>