Dim Oupfilestream
Class Upload_file
Dim form,file,version
Private Sub Class_Initialize
' Define variables
Dim requestbindate,sstart,bcrlf,sinfo,iinfostart,iinfoend,tstream,istart,ofileinfo
Dim ifilesize,sfilepath,sfiletype,sformvalue,sfilename
Dim ifindstart,ifindend
Dim iformstart,iformend,sformname
' Code starts
version= "No component upload class Version 0.96"
Set Form = Server.CreateObject ("Scripting.Dictionary")
Set File = Server.CreateObject ("Scripting.Dictionary")
If Request.TotalBytes < 1 then Exit Sub
Set tstream = Server.CreateObject ("ADODB.stream")
Set oupfilestream = Server.CreateObject ("ADODB.stream")
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 (+) & ChrB (10)
' Get the separator between each item
Sstart = MidB (requestbindate,1, InStrB (1,REQUESTBINDATE,BCRLF)-1)
IStart = LenB (Sstart)
Iformstart = istart+2
' Explode project
Todo
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 form Item name
Iformstart = InStrB (iinfoend,requestbindate,sstart)-1
Ifindstart = InStr (22,sinfo, "name=" "", 1) +6
Ifindend = InStr (Ifindstart,sinfo, "" "", 1)
Sformname = Mid (Sinfo,ifindstart,ifindend-ifindstart)
' If it's a file
If InStr (45,sinfo, "filename=" "", 1) > 0 Then
Set ofileinfo= new FileInfo
' Get file properties
Ifindstart = InStr (Ifindend,sinfo, "filename=" "", 1) +10
Ifindend = InStr (Ifindstart,sinfo, "" "", 1)
sFileName = Mid (Sinfo,ifindstart,ifindend-ifindstart)
Ofileinfo.filename = GetFileName (sfilename)
Ofileinfo.filepath = GetFilePath (sfilename)
Ofileinfo.fileext = Getfileext (sfilename)
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
' If it is a form item
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
Form. ADD Sformname,sformvalue
End If
Tstream.close
Iformstart = iformstart+istart+2
' If you get to the end of the file, quit.
Loop until (iformstart+2) = Iformend
Requestbindate= ""
Set Tstream = Nothing
End Sub
Private Sub class_terminate
' Clear variables and to
if not request.totalbytes<1 then
Oupfilestream.close
set oupfilestream =nothing
End If
Form.removeall
File.removeall
set form=nothing
set file=nothing
End Sub
&NBSP;&N Bsp
Get file path
Private function GetFilePath (fullpath)
If fullpath <> "Then
&nb Sp GetFilePath = Left (Fullpath,instrrev (FullPath, ""))
Else
getfilepath = ""
End If
End Function
' get filename
Private function GetFileName (fullpath)
If Fullpat H <> "" Then
GetFileName = Mid (Fullpath,instrrev (FullPath, "") +1)
Else
getfilename = "
end If
End Function
' Get extension
Private function Getfileext (fullpath)
If fullpath <> "" Then
Getfileext = Mid (Fullpath,instrrev (FullPath, ".") +1)
Else
Getfileext = ""
End If
End Function
End Class
' File attribute Class
Class FileInfo
Dim formname,filename,filepath,filesize,filetype,filestart,fileext
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
filestart= 0
FormName = ""
FileType = ""
Fileext = ""
End Sub
' Save File Method
Public Function SaveToFile (fullpath)
Dim ofilestream,errorchar,i
Savetofile=1
If trim (fullpath) = "" or right (fullpath,1) = "/" Then Exit function
Set Ofilestream=createobject ("ADODB.stream")
Ofilestream.type=1
Ofilestream.mode=3
Ofilestream.open
Oupfilestream.position=filestart
Oupfilestream.copyto ofilestream,filesize
Ofilestream.savetofile fullpath,2
Ofilestream.close
Set ofilestream=nothing
Savetofile=0
End Function
End Class