一聚教程网:一个值得你收藏的教程网站

热门教程

无组件上载,带进度条,多文件上载二

时间:2022-07-02 23:20:52 编辑:袖梨 来源:一聚教程网

n = 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 If
    End Function
 
    Private Function GetFileName(FullPath)
        If FullPath <> "" Then
          GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
        Else
          GetFileName = ""
        End If
    End Function
End Class

 

Class FileInfo
  Dim FormName,FileName,FilePath,FileSize,FileType,FileStart
  Private Sub Class_Initialize
    FileName = ""
    FilePath = ""
    FileSize = 0
    FileStart= 0
    FormName = ""
    FileType = ""
  End Sub
 
    Public Function SaveAs(FullPath)
        Dim dr,ErrorChar,i
        SaveAs=True
  ''Response.Write fullpath & ".....................
"
  ''FileName="ss.txt"
        If trim(fullpath)="" or FileStart=0 or fileName="" or right(fullpath,1)="/" Then Exit Function
  ''Response.Write "2........................
"
        Set dr=CreateObject("Adodb.Stream")
        dr.Mode=3
        dr.Type=1
        dr.Open
        SundyUpload_SourceData.position=FileStart
        SundyUpload_SourceData.copyto dr,FileSize
        dr.SaveToFile FullPath,2
        dr.Close
        Set dr=Nothing
        SaveAs=False
    End Function
End Class

Class Progress
  Dim objDom,xmlPath
    Dim startTime
  Private Sub Class_Initialize

    End Sub
   
    Public Sub ProgressInit(xmlPathTmp)
      Dim objRoot,objChild
        Dim objPI

 

        xmlPath = xmlPathTmp
        Set objDom = Server.CreateObject("Microsoft.XMLDOM")
        Set objRoot = objDom.createElement("progress")
        objDom.appendChild objRoot
       
        Set objChild = objDom.createElement("totalbytes")
        objChild.Text = "0"
        objRoot.appendChild objChild
        Set objChild = objDom.createElement("uploadbytes")
        objChild.Text = "0"
        objRoot.appendChild objChild
        Set objChild = objDom.createElement("uploadpercent")
        objChild.Text = "0%"
        objRoot.appendChild objChild
        Set objChild = objDom.createElement("uploadspeed")
        objChild.Text = "0"
        objRoot.appendChild objChild
        Set objChild = objDom.createElement("totaltime")
        objChild.Text = "00:00:00"
        objRoot.appendChild objChild
        Set objChild = objDom.createElement("lefttime")
        objChild.Text = "00:00:00"
        objRoot.appendChild objChild
       
        Set objPI = objDom.createProcessingInstruction("xml","version=''1.0'' encoding=''utf-8''")
        objDom.insertBefore objPI, objDom.childNodes(0)
        objDom.Save xmlPath
        Set objPI = Nothing
        Set objChild = Nothing
        Set objRoot = Nothing
        Set objDom = Nothing
    End Sub
   
    Sub UpdateProgress(tBytes,rBytes)
      Dim eTime,currentTime,speed,totalTime,leftTime,percent
        If rBytes = 0 Then
            startTime = Timer
            Set objDom = Server.CreateObject("Microsoft.XMLDOM")
            objDom.load(xmlPath)
            objDom.selectsinglenode("//totalbytes").text=tBytes
            objDom.save(xmlPath)
        Else
          speed = 0.0001
          currentTime = Timer
        eTime = currentTime - startTime
            If eTime>0 Then speed = rBytes / eTime
            totalTime = tBytes / speed
            leftTime = (tBytes - rBytes) / speed
            percent = Round(rBytes *100 / tBytes)
            ''objDom.selectsinglenode("//uploadbytes").text = rBytes
            ''objDom.selectsinglenode("//uploadspeed").text = speed
            ''objDom.selectsinglenode("//totaltime").text = totalTime
            ''objDom.selectsinglenode("//lefttime").text = leftTime
            objDom.selectsinglenode("//uploadbytes").text = FormatFileSize(rBytes) & " / " & FormatFileSize(tBytes)
            objDom.selectsinglenode("//uploadpercent").text = percent
            objDom.selectsinglenode("//uploadspeed").text = FormatFileSize(speed) & "/sec"
            objDom.selectsinglenode("//totaltime").text = SecToTime(totalTime)
            objDom.selectsinglenode("//lefttime").text = SecToTime(leftTime)
            objDom.save(xmlPath)       
        End If
    End Sub

 

   private Function SecToTime(sec)
        Dim h:h = "0"
        Dim m:m = "0"
        Dim s:s = "0"
        h = round(sec / 3600)
        m = round( (sec mod 3600) / 60)
        s = round(sec mod 60)
        If LEN(h)=1 Then h = "0" & h
        If LEN(m)=1 Then m = "0" & m
        If LEN(s)=1 Then s = "0" & s
        SecToTime = (h & ":" & m & ":" & s)
    End Function
       
    private Function FormatFileSize(fsize)
        Dim radio,k,m,g,unitTMP
        k = 1024
        m = 1024*1024
        g = 1024*1024*1024
        radio = 1
        If Fix(fsize / g) > 0.0 Then
            unitTMP = "GB"
            radio = g
        ElseIf Fix(fsize / m) > 0 Then
            unitTMP = "MB"
            radio = m
        ElseIf Fix(fsize / k) > 0 Then
            unitTMP = "KB"
            radio = k
        Else
            unitTMP = "B"
            radio = 1
        End If
        If radio = 1 Then
            FormatFileSize = fsize & " " & unitTMP
        Else
            FormatFileSize = FormatNumber(fsize/radio,3) & unitTMP
        End If
    End Function

    Private Sub Class_Terminate 
      Set objDom = Nothing
    End Sub
End Class
''http://www.111com.net/
%>