各种ASP无组件上载,带进度条的实在太多,用起来也不方便,今天自己写了一个,希望大家给点意见
页面都是UTF-8 编码的,用的时候可根据自己页面编码转换 数据挖掘研究院 核心编码:SundyUpload.asp 例子:Example.asp
SundyUpload.asp代码如下: 数据挖掘论坛 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 数据挖掘实验室
<%
Dim SundyUpload_SourceData
Class SundyUpload
Dim objForm,objFile,Version,objProgress
Dim xmlPath,CharsetEncoding 数据挖掘实验室
Public Function Form(strForm)
strForm=lcase(strForm)
If NOT objForm.exists(strForm) Then
Form=""
Else
Form=objForm(strForm)
End If 数据挖掘工具
End Function

Public Function File(strFile)
strFile=lcase(strFile) 数据挖掘实验室
If NOT objFile.exists(strFile) Then
Set File=new FileInfo
Else 数据挖掘交友
Set File=objFile(strFile)
End If
End Function
数据挖掘工具
Public Sub UploadInit(progressXmlPath,charset)
Dim RequestData,sStart,Crlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
Dim iFileSize,sFilePath,sFileType,sFormValue,sFileName 数据挖掘交友
Dim iFindStart,iFindEnd
Dim iFormStart,iFormEnd,sFormName
Version="Upload Width Progress Bar Version 1.0" 数据挖掘交友
Set objForm=Server.CreateObject("Scripting.Dictionary")
Set objFile=Server.CreateObject("Scripting.Dictionary") 数据挖掘实验室
If Request.TotalBytes<1 Then Exit Sub
Set tStream = Server.CreateObject("adodb.stream") 数据挖掘交友
Set SundyUpload_SourceData = Server.CreateObject("adodb.stream")
SundyUpload_SourceData.Type = 1
SundyUpload_SourceData.Mode =3 数据挖掘研究院
SundyUpload_SourceData.Open
Dim TotalBytes
Dim ChunkReadSize
Dim DataPart, PartSize 数据挖掘实验室
Dim objProgress
TotalBytes = Request.TotalBytes " 总大小
ChunkReadSize = 64 * 1024 " 分块大小64K 数据挖掘实验室
BytesRead = 0
xmlPath = progressXmlPath
CharsetEncoding = charset
If CharsetEncoding = "" Then 数据挖掘交友
CharsetEncoding = "utf-8"
End If
Set objProgress = New Progress 数据挖掘实验室
objProgress.ProgressInit(xmlPath)
objProgress.UpdateProgress Totalbytes,0
"循环分块读取
Do While BytesRead < TotalBytes 数据挖掘研究院
"分块读取
PartSize = ChunkReadSize
If PartSize + BytesRead > TotalBytes Then PartSize = TotalBytes - BytesRead 数据挖掘交友
DataPart = Request.BinaryRead(PartSize)
BytesRead = BytesRead + PartSize
SundyUpload_SourceData.Write DataPart 数据挖掘论坛
objProgress.UpdateProgress Totalbytes,BytesRead
Loop
"SundyUpload_SourceData.Write Request.BinaryRead(Request.TotalBytes) 数据挖掘工具
SundyUpload_SourceData.Position=0
RequestData =SundyUpload_SourceData.Read
iFormStart = 1 数据挖掘论坛
iFormEnd = LenB(RequestData)
Crlf = chrB(13) & chrB(10)
sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,Crlf)-1) 数据挖掘论坛
iStart = LenB (sStart)
iFormStart=iFormStart+iStart+1
While (iFormStart + 10) < iFormEnd 数据挖掘实验室
iInfoEnd = InStrB(iFormStart,RequestData,Crlf & Crlf)+3
tStream.Type = 1
tStream.Mode =3 数据挖掘交友
tStream.Open
SundyUpload_SourceData.Position = iFormStart
SundyUpload_SourceData.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.Charset =CharsetEncoding
sInfo = tStream.ReadText
tStream.Close
"取得表单项目名称
iFormStart = InStrB(iInfoEnd,RequestData,sStart)
iFindStart = InStr(22,sInfo,"name=""",1)+6 数据挖掘研究院
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart)) 数据挖掘论坛
"如果是文件
If InStr (45,sInfo,"filename=""",1) > 0 Then
Set theFile=new FileInfo
"取得文件名
iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10 数据挖掘论坛
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart) 数据挖掘交友
theFile.FileName=getFileName(sFileName)
theFile.FilePath=getFilePath(sFileName)
"取得文件类型
iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr(iFindStart,sInfo,vbCr)
theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileStart =iInfoEnd
theFile.FileSize = iFormStart -iInfoEnd -3 数据挖掘交友
theFile.FormName=sFormName
If NOT objFile.Exists(sFormName) Then
objFile.add sFormName,theFile
End If
Else
"如果是表单项目
tStream.Type =1
tStream.Mode =3
tStream.Open 数据挖掘实验室
SundyUpload_SourceData.Position = iInfoEnd
SundyUpload_SourceData.CopyTo tStream,iFormStart-iInfoEnd-3
tStream.Position = 0
tStream.Type = 2
tStream.Charset = CharsetEncoding
sFormValue = tStream.ReadText 数据挖掘论坛
tStream.Close
If objForm.Exists(sFormName) Then
objForm(sFormName)=objForm(sFormName)&", "&sFormValue 数据挖掘交友
Else
objForm.Add sFormName,sFormValue
End If
End If
iFormStart=iFormStart+iStart+1
Wend
RequestData="" 数据挖掘实验室
Set tStream = Nothing
End Sub
Private Sub Class_Initialize
End Sub
Private Sub Class_Terminate
If Request.TotalBytes>0 Then 数据挖掘交友
objForm.RemoveAll
objFile.RemoveAll
Set objForm=Nothing
Set objFile=Nothing
SundyUpload_SourceData.Close
Set SundyUpload_SourceData = Nothing
End If
Set objProgress = Nothing
Set objFso = Server.CreateObject("Scripting.FileSystemObject") 数据挖掘实验室
If objFso.FileExists(xmlPath) Then
objFso.DeleteFile(xmlPath)
End If
Set objFso = Nothing 数据挖掘研究院
End Sub
Private Function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, ""))
Else
GetFilePath = "" 数据挖掘研究院
End
|