upload_5xsoft.inc
资源名称:1.rar [点击查看]
上传用户:ziqing_518
上传日期:2022-08-09
资源大小:446k
文件大小:5k
源码类别:

多媒体编程

开发平台:

ASP/ASPX

  1. <SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
  2. dim upfile_5xSoft_Stream
  3. Class upload_5xSoft
  4.   
  5. dim Form,File,Version
  6.   
  7. Private Sub Class_Initialize 
  8. dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
  9. dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
  10. Version="上传程序"
  11. if Request.TotalBytes<1 then Exit Sub
  12. set Form=CreateObject("Scripting.Dictionary")
  13. set File=CreateObject("Scripting.Dictionary")
  14. set upfile_5xSoft_Stream=CreateObject("Adodb.Stream")
  15. upfile_5xSoft_Stream.mode=3
  16. upfile_5xSoft_Stream.type=1
  17. upfile_5xSoft_Stream.open
  18. upfile_5xSoft_Stream.write Request.BinaryRead(Request.TotalBytes)
  19. vbEnter=Chr(13)&Chr(10)
  20. iDivLen=inString(1,vbEnter)+1
  21. strDiv=subString(1,iDivLen)
  22. iFormStart=iDivLen
  23. iFormEnd=inString(iformStart,strDiv)-1
  24. while iFormStart < iFormEnd
  25.   iStart=inString(iFormStart,"name=""")
  26.   iEnd=inString(iStart+6,"""")
  27.   mFormName=subString(iStart+6,iEnd-iStart-6)
  28.   iFileNameStart=inString(iEnd+1,"filename=""")
  29.   if iFileNameStart>0 and iFileNameStart<iFormEnd then
  30.    iFileNameEnd=inString(iFileNameStart+10,"""")
  31.    mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
  32.    iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
  33.    iEnd=inString(iStart+4,vbEnter&strDiv)
  34.    if iEnd>iStart then
  35.     mFileSize=iEnd-iStart-4
  36.    else
  37.     mFileSize=0
  38.    end if
  39.    set theFile=new FileInfo
  40.    theFile.FileName=getFileName(mFileName)
  41.    theFile.FilePath=getFilePath(mFileName)
  42.    theFile.FileSize=mFileSize
  43.    theFile.FileStart=iStart+4
  44.    theFile.FormName=FormName
  45.    file.add mFormName,theFile
  46.   else
  47.    iStart=inString(iEnd+1,vbEnter&vbEnter)
  48.    iEnd=inString(iStart+4,vbEnter&strDiv)
  49.    if iEnd>iStart then
  50.     mFormValue=subString(iStart+4,iEnd-iStart-4)
  51.    else
  52.     mFormValue="" 
  53.    end if
  54.    form.Add mFormName,mFormValue
  55.   end if
  56.   iFormStart=iformEnd+iDivLen
  57.   iFormEnd=inString(iformStart,strDiv)-1
  58. wend
  59. End Sub
  60. Private Function subString(theStart,theLen)
  61.  dim i,c,stemp
  62.  upfile_5xSoft_Stream.Position=theStart-1
  63.  stemp=""
  64.  for i=1 to theLen
  65.    if upfile_5xSoft_Stream.EOS then Exit for
  66.    c=ascB(upfile_5xSoft_Stream.Read(1))
  67.    If c > 127 Then
  68.     if upfile_5xSoft_Stream.EOS then Exit for
  69.     stemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))
  70.     i=i+1
  71.    else
  72.     stemp=stemp&Chr(c)
  73.    End If
  74.  Next
  75.  subString=stemp
  76. End function
  77. Private Function inString(theStart,varStr)
  78.  dim i,j,bt,theLen,str
  79.  InString=0
  80.  Str=toByte(varStr)
  81.  theLen=LenB(Str)
  82.  for i=theStart to upfile_5xSoft_Stream.Size-theLen
  83.    if i>upfile_5xSoft_Stream.size then exit Function
  84.    upfile_5xSoft_Stream.Position=i-1
  85.    if AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1)) then
  86.     InString=i
  87.     for j=2 to theLen
  88.       if upfile_5xSoft_Stream.EOS then 
  89.         inString=0
  90.         Exit for
  91.       end if
  92.       if AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
  93.         InString=0
  94.         Exit For
  95.       end if
  96.     next
  97.     if InString<>0 then Exit Function
  98.    end if
  99.  next
  100. End Function
  101. Private Sub Class_Terminate  
  102.   form.RemoveAll
  103.   file.RemoveAll
  104.   set form=nothing
  105.   set file=nothing
  106.   upfile_5xSoft_Stream.close
  107.   set upfile_5xSoft_Stream=nothing
  108. End Sub
  109.    
  110.  
  111.  Private function GetFilePath(FullPath)
  112.   If FullPath <> "" Then
  113.    GetFilePath = left(FullPath,InStrRev(FullPath, ""))
  114.   Else
  115.    GetFilePath = ""
  116.   End If
  117.  End  function
  118.  
  119.  Private function GetFileName(FullPath)
  120.   If FullPath <> "" Then
  121.    GetFileName = mid(FullPath,InStrRev(FullPath, "")+1)
  122.   Else
  123.    GetFileName = ""
  124.   End If
  125.  End  function
  126.  Private function toByte(Str)
  127.    dim i,iCode,c,iLow,iHigh
  128.    toByte=""
  129.    For i=1 To Len(Str)
  130.    c=mid(Str,i,1)
  131.    iCode =Asc(c)
  132.    If iCode<0 Then iCode = iCode + 65535
  133.    If iCode>255 Then
  134.      iLow = Left(Hex(Asc(c)),2)
  135.      iHigh =Right(Hex(Asc(c)),2)
  136.      toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
  137.    Else
  138.      toByte = toByte & chrB(AscB(c))
  139.    End If
  140.    Next
  141.  End function
  142. End Class
  143. Class FileInfo
  144.   dim FormName,FileName,FilePath,FileSize,FileStart
  145.   Private Sub Class_Initialize 
  146.     FileName = ""
  147.     FilePath = ""
  148.     FileSize = 0
  149.     FileStart= 0
  150.     FormName = ""
  151.   End Sub
  152.   
  153.  Public function SaveAs(FullPath)
  154.     dim dr,ErrorChar,i
  155.     SaveAs=1
  156.     if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
  157.     if FileStart=0 or right(fullpath,1)="/" then exit function
  158.     set dr=CreateObject("Adodb.Stream")
  159.     dr.Mode=3
  160.     dr.Type=1
  161.     dr.Open
  162.     upfile_5xSoft_Stream.position=FileStart-1
  163.     upfile_5xSoft_Stream.copyto dr,FileSize
  164.     dr.SaveToFile FullPath,2
  165.     dr.Close
  166.     set dr=nothing 
  167.     SaveAs=0
  168.   end function
  169. End Class
  170. </SCRIPT>