<% '---------------------------------------------------------------------- 'Keep this declaration information during forwarding. This declaration does not affect your speed! **************** ******************** 'Copyright: All rights reserved. The source code is public and can be used for all purposes free of charge. However, after modification, the modified file must be 'Send a copy to the author and retain the author's copyright information. '*************************************** ******************************* '---------------------------------------------------------------------- Dim oUpFileStream '---------------------------------------------------------------------- 'File Upload class Class UpFile_Class Dim Form, File, Version, Err Private Sub Class_Initialize Version = "no fear of uploading class Version V1.2" Err =-1 End Sub Private Sub Class_Terminate 'Clear variables and objects If Err <0 Then Form. RemoveAll Set Form = Nothing File. RemoveAll Set File = Nothing OUpFileStream. Close Set oUpFileStream = Nothing End If End Sub Public Sub GetData (MaxSize) 'Define variables Dim RequestBinDate, sSpace, bCrLf, sInfo, iInfoStart, iInfoEnd, tStream, iStart, oFileInfo Dim iFileSize, sFilePath, sFileType, sFormValue, sFileName Dim iFindStart, iFindEnd Dim iFormStart, iFormEnd, sFormName 'Code starts If Request. TotalBytes <1 then', If no data is uploaded Err = 1 Exit Sub End If If MaxSize> 0 then', If the size is limited If Request. TotalBytes> MaxSize Then Err = 2' if the uploaded data exceeds the limit Exit Sub End If End If Set Form = Server. CreateObject ("Scripting. Dictionary ") Form. CompareMode = 1 Set File = Server. CreateObject ("Scripting. Dictionary ") File. CompareMode = 1 Set tStream = Server. CreateObject ("Ado" & "db. Str" & "eam ") Set oUpFileStream = Server. CreateObject ("Ado" & "db. Str" & "eam ") OUpFileStream. Type = 1 OUpFileStream. Mode = 3 OUpFileStream. Open OUpFileStream. Write Request. BinaryRead (Request. TotalBytes) OUpFileStream. Position = 0 RequestBinDate = oUpFileStream. Read IFormEnd = oUpFileStream. Size BCrLf = ChrB (13) & ChrB (10) 'Get the delimiter between each project SSpace = MidB (RequestBinDate, 1, Region B (1, RequestBinDate, bCrLf)-1) IStart = LenB (sSpace) IFormStart = iStart + 2 'Project breakdown Do IInfoEnd = InStrB (iFormStart, RequestBinDate, bCrLf & bCrLf) + 3 TStream. Type = 1 TStream. Mode = 3 TStream. Open OUpFileStream. Position = iFormStart OUpFileStream. CopyTo tStream, iInfoEnd-iFormStart TStream. Position = 0 TStream. Type = 2 TStream. CharSet = "gb2312" SInfo = tStream. ReadText 'Get the form project name IFormStart = required B (iInfoEnd, RequestBinDate, sSpace)-1 IFindStart = InStr (22, sInfo, "name =", 1) + 6 IFindEnd = InStr (iFindStart, sInfo, ", 1) SFormName = Mid (sinfo, iFindStart, iFindEnd-iFindStart) 'If it is a file If InStr (45, sInfo, "filename =", 1)> 0 Then Set oFileInfo = new FileInfo_Class 'Get file attributes IFindStart = InStr (iFindEnd, sInfo, "filename =", 1) + 10 IFindEnd = InStr (iFindStart, sInfo, ", 1) SFileName = Mid (sinfo, iFindStart, iFindEnd-iFindStart) OFileInfo. FileName = Mid (sFileName, limit Rev (sFileName, "\") + 1) OFileInfo. FilePath = Left (sFileName, limit Rev (sFileName ,"\")) OFileInfo. FileExt = Mid (sFileName, limit Rev (sFileName, ".") + 1) IFindStart = InStr (iFindEnd, sInfo, "Content-Type:", 1) + 14 IFindEnd = InStr (iFindStart, sInfo, vbCr) OFileInfo. FileType = Mid (sinfo, iFindStart, iFindEnd-iFindStart) OFileInfo. FileStart = iInfoEnd OFileInfo. FileSize = iFormStart-iInfoEnd-2 OFileInfo. FormName = sFormName File. add sFormName, oFileInfo Else 'For a form project TStream. Close TStream. Type = 1 TStream. Mode = 3 TStream. Open OUpFileStream. Position = iInfoEnd OUpFileStream. CopyTo tStream, iFormStart-iInfoEnd-2 TStream. Position = 0 TStream. Type = 2 TStream. CharSet = "gb2312" SFormValue = tStream. ReadText If Form. Exists (sFormName) Then Form (sFormName) = Form (sFormName) & "," & sFormValue Else Form. Add sFormName, sFormValue End If End If TStream. Close IFormStart = iFormStart + iStart + 2 'Exit if the end of the file is reached. Loop Until (iFormStart + 2)> = iFormEnd RequestBinDate = "" Set tStream = Nothing End Sub End Class 'Timeout '---------------------------------------------------------------------------------------------------- 'File attribute class Class FileInfo_Class Dim FormName, FileName, FilePath, FileSize, FileType, FileStart, FileExt 'File saving method Public Function SaveToFile (Path) On Error Resume Next Dim oFileStream Set oFileStream = CreateObject ("Ado" & "db. Str" & "eam ") OFileStream. Type = 1 OFileStream. Mode = 3 OFileStream. Open OUpFileStream. Position = FileStart OUpFileStream. CopyTo oFileStream, FileSize OFileStream. SaveToFile Path, 2 OFileStream. Close Set oFileStream = Nothing End Function 'Get file data Public Function FileData OUpFileStream. Position = FileStart FileData = oUpFileStream. Read (FileSize) End Function End Class %> |