UpFileClass.asp
上传用户:dbstep
上传日期:2022-08-06
资源大小:2803k
文件大小:5k
源码类别:

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

开发平台:

ASP/ASPX

  1. <!--#include file="CheckAdmin.asp"-->
  2. <%
  3. Dim oUpFileStream 
  4. Class UpFile_Class
  5.   Dim Form,File,Version,Err
  6.    
  7.   Private Sub Class_Initialize
  8.     Version = "NWEBCN无组件上传类 Version V1.0"
  9.     Err = -1
  10.   End Sub
  11.   Private Sub Class_Terminate 
  12.     '清除变量及对像
  13.     If Err < 0 Then
  14.       Form.RemoveAll
  15.       Set Form = Nothing
  16.       File.RemoveAll
  17.       Set File = Nothing
  18.       oUpFileStream.Close
  19.       Set oUpFileStream = Nothing
  20.     End If
  21.   End Sub
  22.   Public Sub GetData (RetSize)
  23.     '定义变量
  24.     Dim RequestBinDate,sSpace,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
  25.     Dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
  26.     Dim iFindStart,iFindEnd
  27.     Dim iFormStart,iFormEnd,sFormName
  28.     '代码开始
  29.     If Request.TotalBytes < 1 Then
  30.       Err = 1
  31.       Exit Sub
  32.     End If
  33.     If RetSize > 0 Then 
  34.       If Request.TotalBytes > RetSize Then
  35.         Err = 2
  36.         Exit Sub
  37.       End If
  38.     End If
  39.     Set Form = Server.CreateObject ("Scripting.Dictionary")
  40.     Form.CompareMode = 1
  41.     Set File = Server.CreateObject ("Scripting.Dictionary")
  42.     File.CompareMode = 1
  43.     Set tStream = Server.CreateObject ("ADODB.Stream")
  44.     Set oUpFileStream = Server.CreateObject ("ADODB.Stream")
  45.     oUpFileStream.Type = 1
  46.     oUpFileStream.Mode = 3
  47.     oUpFileStream.Open 
  48.     oUpFileStream.Write Request.BinaryRead (Request.TotalBytes)
  49.     oUpFileStream.Position = 0
  50.     RequestBinDate = oUpFileStream.Read 
  51.     iFormEnd = oUpFileStream.Size
  52.     bCrLf = ChrB (13) & ChrB (10)
  53.     '取得每个项目之间的分隔符
  54.     sSpace = MidB (RequestBinDate,1, InStrB (1,RequestBinDate,bCrLf)-1)
  55.     iStart = LenB (sSpace)
  56.     iFormStart = iStart+2
  57.     '分解项目
  58.     Do
  59.     iInfoEnd = InStrB (iFormStart,RequestBinDate,bCrLf & bCrLf)+3
  60.     tStream.Type = 1
  61.     tStream.Mode = 3
  62.     tStream.Open
  63.     oUpFileStream.Position = iFormStart
  64.     oUpFileStream.CopyTo tStream,iInfoEnd-iFormStart
  65.     tStream.Position = 0
  66.     tStream.Type = 2
  67.     tStream.CharSet = "utf-8"
  68.     sInfo = tStream.ReadText 
  69.     '取得表单项目名称
  70.     iFormStart = InStrB (iInfoEnd,RequestBinDate,sSpace)-1
  71.     iFindStart = InStr (22,sInfo,"name=""",1)+6
  72.     iFindEnd = InStr (iFindStart,sInfo,"""",1)
  73.     sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
  74.     '如果是文件
  75.     If InStr (45,sInfo,"FileName=""",1) > 0 Then
  76.       Set oFileInfo = new FileInfo_Class
  77.       '取得文件属性
  78.       iFindStart = InStr (iFindEnd,sInfo,"FileName=""",1)+10
  79.       iFindEnd = InStr (iFindStart,sInfo,"""",1)
  80.       sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
  81.       oFileInfo.FileName = Mid (sFileName,InStrRev (sFileName, "")+1)
  82.       oFileInfo.FilePath = Left (sFileName,InStrRev (sFileName, "")+1)
  83.       oFileInfo.FileExt = Mid (sFileName,InStrRev (sFileName, ".")+1)
  84.       iFindStart = InStr (iFindEnd,sInfo,"Content-Type: ",1)+14
  85.       iFindEnd = InStr (iFindStart,sInfo,vbCr)
  86.       oFileInfo.FileType = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
  87.       oFileInfo.FileStart = iInfoEnd
  88.       oFileInfo.FileSize = iFormStart -iInfoEnd -2
  89.       oFileInfo.FormName = sFormName
  90.       file.add sFormName,oFileInfo
  91.     else
  92.       '如果是表单项目
  93.       tStream.Close
  94.       tStream.Type = 1
  95.       tStream.Mode = 3
  96.       tStream.Open
  97.       oUpFileStream.Position = iInfoEnd 
  98.       oUpFileStream.CopyTo tStream,iFormStart-iInfoEnd-2
  99.       tStream.Position = 0
  100.       tStream.Type = 2
  101.       tStream.CharSet = "utf-8"
  102.       sFormValue = tStream.ReadText
  103.       If Form.Exists (sFormName) Then
  104.         Form (sFormName) = Form (sFormName) & ", " & sFormValue
  105.       else
  106.         form.Add sFormName,sFormValue
  107.       End If
  108.     End If
  109.     tStream.Close
  110.     iFormStart = iFormStart+iStart+2
  111.     '如果到文件尾了就退出
  112.     Loop Until (iFormStart+2) = iFormEnd 
  113.     RequestBinDate = ""
  114.     Set tStream = Nothing
  115.   End Sub
  116. End Class
  117. '文件属性类
  118. Class FileInfo_Class
  119.   Dim FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt
  120. '保存文件方法
  121.   Public Function SaveToFile (Path)
  122.     On Error Resume Next
  123.     Dim oFileStream
  124.     Set oFileStream = CreateObject ("ADODB.Stream")
  125.     oFileStream.Type = 1
  126.     oFileStream.Mode = 3
  127.     oFileStream.Open
  128.     oUpFileStream.Position = FileStart
  129.     oUpFileStream.CopyTo oFileStream,FileSize
  130.     oFileStream.SaveToFile Path,2
  131.     oFileStream.Close
  132.     Set oFileStream = Nothing
  133.     if Err.Number<>0 then
  134.       SaveToFile=err.number&"**"&Err.descripton
  135.     else
  136.       SaveToFile="ok"
  137.     end if
  138.   End Function
  139.   '取得文件数据
  140.   Public Function FileDate
  141.     oUpFileStream.Position = FileStart
  142.     FileDate = oUpFileStream.Read (FileSize)
  143.   End Function
  144. End Class
  145. %>