刚接触此组件时就被它功能强大与灵活方便吸引,由于当时项目采用asp开发,百度一番后发现并无好用的asp上传处理程序(现在有很多啦^^),看来只能自己研究开发啦,最初采用处理普通上传的方法来截取文件的数据,几经测试发现并不能有效接收组件传递过来的文件数据,无奈只能着手分析下它发送的数据形式,通过分析发现它发送的数据格式还是和普通上传存在一些区别的,无论是图片还是文件都是以octet-stream形式发送到服务器的,了解了数据格式,剩下的就是截取啦,下面把我的处理方法分享给需要的朋友,处理速度还算理想。
复制代码 代码如下:
<%
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)
内容版权声明:除非注明,否则皆为本站原创文章。