zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

为SWFUpload增加ASP版本的上传处理程序

ASP上传 版本 增加 处理程序 SWFUpload
2023-06-13 09:14:27 时间
但也许是随着asp的逐渐淡出web开发,官方仅提供了.net、php等版本的上传处理程序,对于asp开发者来说则需要自行处理服务器端的数据接收。

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

<%
ClassSWFUpload

PrivateformData,folderPath,streamGet
PrivatefileSize,chunkSize,bofCont,eofCont

REMCLASS-INITIALIZE

PrivateSubClass_Initialize
CallInitVariant
Server.ScriptTimeOut=1800
SetstreamGet=Server.CreateObject("ADODB.Stream")

sAuthor="51JS.COM-ZMM"
sVersion="UploadClass1.0"
EndSub

REMCLASS-INITIALIZE

PublicPropertyLetSaveFolder(byValsFolder)
IfRight(sFolder,1)="/"Then
folderPath=sFolder
Else
folderPath=sFolder&"/"
EndIf
EndProperty

PublicPropertyGetSaveFolder
SaveFolder=folderPath
EndProperty

PrivateFunctionInitVariant
chunkSize=1024*128

folderPath="/":fileSize=1024*10
bofCont=StrToByte("octet-stream"&vbCrlf&vbCrlf)
eofCont=StrToByte(vbCrlf&String(12,"-"))
EndFunction

PublicFunctionGetUploadData
DimcurRead:curRead=0
DimdataLen:dataLen=Request.TotalBytes

streamGet.Type=1:streamGet.Open
DoWhilecurRead<dataLen
DimpartLen:partLen=chunkSize
IfpartLen+curRead>dataLenThenpartLen=dataLen-curRead
streamGet.WriteRequest.BinaryRead(partLen)
curRead=curRead+partLen
Loop
streamGet.Position=0
formData=streamGet.Read(dataLen)

CallGetUploadFile
EndFunction

PublicFunctionGetUploadFile
DimbegMark:begMark=StrToByte("filename=")
DimbegPath:begPath=InStrB(1,formData,begMark&ChrB(34))+10
DimendPath:endPath=InStrB(begPath,formData,ChrB(34))
DimcntPath:cntPath=MidB(formData,begPath,endPath-begPath)
DimcntName:cntName=folderPath&GetClientName(cntPath)

DimbegFile:begFile=InStrB(1,formData,bofCont)+15
DimendFile:endFile=InStrB(begFile,formData,eofCont)

CallSaveUploadFile(cntName,begFile,endFile-begFile)
EndFunction

PublicFunctionSaveUploadFile(byValfName,byValbCont,byValsLen)
DimfilePath:filePath=Server.MapPath(fName)
IfCreateFolder("|",GetParentFolder(filePath))Then
streamGet.Position=bCont
SetstreamPut=Server.CreateObject("ADODB.Stream")
streamPut.Type=1:streamPut.Mode=3:streamPut.Open
streamPut.WritestreamGet.Read(sLen)
streamPut.SaveToFilefilePath,2
streamPut.Close:SetstreamPut=Nothing
EndIf
EndFunction

PrivateFunctionIsNothing(byValsVar)
IsNothing=IsNull(sVar)Or(sVar=Empty)
EndFunction

PrivateFunctionStrToByte(byValsText)
Fori=1ToLen(sText)
StrToByte=StrToByte&ChrB(Asc(Mid(sText,i,1)))
Next
EndFunction

PrivateFunctionByteToStr(byValsByte)
DimstreamTmp
SetstreamTmp=Server.CreateObject("ADODB.Stream")
streamTmp.Type=2
streamTmp.Mode=3
streamTmp.Open
streamTmp.WriteTextsByte
streamTmp.Position=0
streamTmp.CharSet="utf-8"
streamTmp.Position=2
ByteToStr=streamTmp.ReadText
streamTmp.Close
SetstreamTmp=Nothing
EndFunction

PrivateFunctionGetClientName(byValbInfo)
DimsInfo,regEx
sInfo=ByteToStr(bInfo)
IfIsNothing(sInfo)Then
GetClientName=""
Else
SetregEx=NewRegExp
regEx.Pattern="^.*\\([^\\]+)$"
regEx.Global=False
regEx.IgnoreCase=True
GetClientName=regEx.Replace(sInfo,"$1")
SetregEx=Nothing
EndIf
EndFunction

PrivateFunctionGetParentFolder(byValsPath)
DimregEx
SetregEx=NewRegExp
regEx.Pattern="^(.*)\\[^\\]*$"
regEx.Global=True
regEx.IgnoreCase=True
GetParentFolder=regEx.Replace(sPath,"$1")
SetregEx=Nothing
EndFunction

PrivateFunctionCreateFolder(byValsLine,byValsPath)
DimoFso
SetoFso=Server.CreateObject("Scripting.FileSystemObject")
IfNotoFso.FolderExists(sPath)Then
DimregEx
SetregEx=NewRegExp
regEx.Pattern="^(.*)\\([^\\]*)$"
regEx.Global=False
regEx.IgnoreCase=True
sLine=sLine&regEx.Replace(sPath,"$2")&"|"
sPath=regEx.Replace(sPath,"$1")
IfCreateFolder(sLine,sPath)ThenCreateFolder=True
SetregEx=Nothing
Else
IfsLine="|"Then
CreateFolder=True
Else
DimsTemp:sTemp=Mid(sLine,2,Len(sLine)-2)
IfInStrRev(sTemp,"|")=0Then
sLine="|"
sPath=sPath&"\"&sTemp
Else
DimFolder:Folder=Mid(sTemp,InStrRev(sTemp,"|")+1)
sLine="|"&Mid(sTemp,1,InStrRev(sTemp,"|")-1)&"|"
sPath=sPath&"\"&Folder
EndIf
oFso.CreateFoldersPath
IfCreateFolder(sLine,sPath)ThenCreateFolder=True
Endif
EndIf
SetoFso=Nothing
EndFunction

REMCLASS-TERMINATE

PrivateSubClass_Terminate
streamGet.Close
SetstreamGet=Nothing
EndSub

EndClass

REM调用方法
DimoUpload
SetoUpload=NewSWFUpload
oUpload.SaveFolder="存放路径"
oUpload.GetUploadData
SetoUpload=Nothing
%>