'----------------------------------------------------------------------
'Keep this declaration information during forwarding. This declaration will not affect your speed!
**************** ****************
'The last modifier: snow in Sebei
'Blog: http://blog.csdn.net
'Email: northsnow@163.com
'Declaration: This Code was modified on the basis of the beam unafraid Code. The Code kernel was not changed, but an attribute smallfilename was added.
'The reason why I published this article is to tell you that when using the code written by a master, it should not be limited to the existing functions provided by others,
'And should be based on the existing functions provided by others, according to their own needs. To meet your most satisfactory needs.
'Modifier: Liang wushi
'Email: yjlrb@21cn.com
'Site: http://www.25cn.com
'The Original Author: daoxiang Lao Nong
'Author's website: http://www.5xsoft.com
'Declaration: This upload class was modified based on the component-less upload class released in the chemical programming field.
'The speed is nearly 50 times faster than that of the component-free upload class in the chemical programming field. When uploading a file of 4 MB size
'The server can be processed in just 10 seconds. It is the fastest no-component upload program currently. The current version is 0.96.
'The source code is open for free. Please contact the author for commercial purposes.
'File attributes: for example, the uploaded file is C:/myfile/doc.txt.
'Filenamename string "doc.txt"
'Filesize file size value: 1210
'Filetype file type string "text/plain"
'Fileext file extension string "TXT"
'Smallfilename removes the extension file name "Doc"
'Filepath file original path string "C:/myfile"
'Precautions during use:
'Because scripting. dictionary is case sensitive, the Project names on webpages and ASP pages must be the same size.
'Write. If you are used to uppercase or lowercase letters, you can
'Sformname = mid (SINFO, ifindstart, ifindend-ifindstart)
'
'(Small writer) sformname = lcase (mid (SINFO, ifindstart, ifindend-ifindstart ))
'(Uppercase) sformname = ucase (mid (SINFO, ifindstart, ifindend-ifindstart ))
'*************************************** *******************************
'----------------------------------------------------------------------
Dim oupfilestream
Class upload_file
Dim form, file
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
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 (13) & chrb (10)
'Get the delimiter between each project
Sstart = midb (requestbindate, 1, Region B (1, requestbindate, bcrlf)-1)
Istart = lenb (sstart)
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, sstart)-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
'Get file attributes
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) '---- modified by Liu jincai
Ofileinfo. fileext = getfileext (ofileinfo. filename) '---- Liu Jin added
Ofileinfo. smallfilename = getsmallfilename (ofileinfo. filename) '---- Liu Jin added
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
Form. Add sformname, sformvalue
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
Private sub class_terminate
'Clear variables and objects
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
'Get file path
Private function getfilepath (fullpath)
If fullpath <> "" then
Getfilepath = left (fullpath, limit Rev (fullpath ,"/"))
Else
Getfilepath = ""
End if
End Function
'Get the full name of the file
Private function getfilename (fullpath)
If fullpath <> "" then
Getfilename = mid (fullpath, limit Rev (fullpath, "/") + 1)
Else
Getfilename = ""
End if
End Function
'Get the extension
Private function getfileext (filename)
If filename <> "" then
If instr (filename, ".")> 0 then
Getfileext = mid (filename, limit Rev (filename, ".") + 1)
Else
Getfileext = ""
End if
Else
Getfileext = ""
End if
End Function
'Liu Jin added the file name with the extension removed
Private function getsmallfilename (filename)
If filename <> "" then
If instr (filename, ".")> 0 then
Getsmallfilename = mid (filename, 1, limit Rev (filename, ".")-1)
Else
Getsmallfilename = filename
End if
Else
Getsmallfilename = ""
End if
End Function
End Class
'File Attribute Class
'The newly added smallfilename indicates that the file name with the extension is removed.
Class fileinfo
Dim formname, filename, filepath, filesize, filetype, filestart, fileext, smallfilename
Private sub class_initialize
Filename = ""
Smallfilename = ""
Filepath = ""
Filesize = 0
Filestart = 0
Formname = ""
Filetype = ""
Fileext = ""
End sub
'File Saving 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