upload.inc
上传用户:comthink
上传日期:2021-05-06
资源大小:1280k
文件大小:5k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

HTML/CSS

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