upload.inc
上传用户:sking1122
上传日期:2020-09-24
资源大小:1005k
文件大小:4k
源码类别:

手机WAP编程

开发平台:

ASP/ASPX

  1. <SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
  2. dim Data_5xsoft
  3. Class upload_5xsoft
  4.   
  5. dim objForm,objFile,Version
  6. Public function Form(strForm)
  7.    strForm=lcase(strForm)
  8.    if not objForm.exists(strForm) then
  9.      Form=""
  10.    else
  11.      Form=objForm(strForm)
  12.    end if
  13.  end function
  14. Public function File(strFile)
  15.    strFile=lcase(strFile)
  16.    if not objFile.exists(strFile) then
  17.      set File=new FileInfo
  18.    else
  19.      set File=objFile(strFile)
  20.    end if
  21.  end function
  22. Private Sub Class_Initialize 
  23.   dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
  24.   dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
  25.   dim iFindStart,iFindEnd
  26.   dim iFormStart,iFormEnd,sFormName
  27.   Version="9Cool.Net WEB上传程序 Version 2.0"
  28.   set objForm=Server.CreateObject("Scripting.Dictionary")
  29.   set objFile=Server.CreateObject("Scripting.Dictionary")
  30.   if Request.TotalBytes<1 then Exit Sub
  31.   set tStream = Server.CreateObject("adodb.stream")
  32.   set Data_5xsoft = Server.CreateObject("adodb.stream")
  33.   Data_5xsoft.Type = 1
  34.   Data_5xsoft.Mode =3
  35.   Data_5xsoft.Open
  36.   Data_5xsoft.Write  Request.BinaryRead(Request.TotalBytes)
  37.   Data_5xsoft.Position=0
  38.   RequestData =Data_5xsoft.Read 
  39.   iFormStart = 1
  40.   iFormEnd = LenB(RequestData)
  41.   vbCrlf = chrB(13) & chrB(10)
  42.   sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
  43.   iStart = LenB (sStart)
  44.   iFormStart=iFormStart+iStart+1
  45.   while (iFormStart + 10) < iFormEnd 
  46. iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3
  47. tStream.Type = 1
  48. tStream.Mode =3
  49. tStream.Open
  50. Data_5xsoft.Position = iFormStart
  51. Data_5xsoft.CopyTo tStream,iInfoEnd-iFormStart
  52. tStream.Position = 0
  53. tStream.Type = 2
  54. tStream.Charset ="gb2312"
  55. sInfo = tStream.ReadText
  56. tStream.Close
  57. '取得表单项目名称
  58. iFormStart = InStrB(iInfoEnd,RequestData,sStart)
  59. iFindStart = InStr(22,sInfo,"name=""",1)+6
  60. iFindEnd = InStr(iFindStart,sInfo,"""",1)
  61. sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
  62. '如果是文件
  63. if InStr (45,sInfo,"filename=""",1) > 0 then
  64. set theFile=new FileInfo
  65. '取得文件名
  66. iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
  67. iFindEnd = InStr(iFindStart,sInfo,"""",1)
  68. sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
  69. theFile.FileName=getFileName(sFileName)
  70. theFile.FilePath=getFilePath(sFileName)
  71. '取得文件类型
  72. iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
  73. iFindEnd = InStr(iFindStart,sInfo,vbCr)
  74. theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart)
  75. theFile.FileStart =iInfoEnd
  76. theFile.FileSize = iFormStart -iInfoEnd -3
  77. theFile.FormName=sFormName
  78. if not objFile.Exists(sFormName) then
  79.   objFile.add sFormName,theFile
  80. end if
  81. else
  82. '如果是表单项目
  83. tStream.Type =1
  84. tStream.Mode =3
  85. tStream.Open
  86. Data_5xsoft.Position = iInfoEnd 
  87. Data_5xsoft.CopyTo tStream,iFormStart-iInfoEnd-3
  88. tStream.Position = 0
  89. tStream.Type = 2
  90. tStream.Charset ="gb2312"
  91.         sFormValue = tStream.ReadText 
  92.         tStream.Close
  93. if objForm.Exists(sFormName) then
  94.   objForm(sFormName)=objForm(sFormName)&", "&sFormValue   
  95. else
  96.   objForm.Add sFormName,sFormValue
  97. end if
  98. end if
  99. iFormStart=iFormStart+iStart+1
  100. wend
  101.   RequestData=""
  102.   set tStream =nothing
  103. End Sub
  104. Private Sub Class_Terminate  
  105.  if Request.TotalBytes>0 then
  106. objForm.RemoveAll
  107. objFile.RemoveAll
  108. set objForm=nothing
  109. set objFile=nothing
  110. Data_5xsoft.Close
  111. set Data_5xsoft =nothing
  112.  end if
  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. End Class
  132. Class FileInfo
  133.   dim FormName,FileName,FilePath,FileSize,FileType,FileStart
  134.   Private Sub Class_Initialize 
  135.     FileName = ""
  136.     FilePath = ""
  137.     FileSize = 0
  138.     FileStart= 0
  139.     FormName = ""
  140.     FileType = ""
  141.   End Sub
  142.   
  143.  Public function SaveAs(FullPath)
  144.     dim dr,ErrorChar,i
  145.     SaveAs=true
  146.     if trim(fullpath)="" or FileStart=0 or FileName="" or right(fullpath,1)="/" then exit function
  147.     set dr=CreateObject("Adodb.Stream")
  148.     dr.Mode=3
  149.     dr.Type=1
  150.     dr.Open
  151.     Data_5xsoft.position=FileStart
  152.     Data_5xsoft.copyto dr,FileSize
  153.     dr.SaveToFile FullPath,2
  154.     dr.Close
  155.     set dr=nothing 
  156.     SaveAs=false
  157.   end function
  158.   End Class
  159. </SCRIPT>