No fear file Upload class Version V1.2

Source: Internet
Author: User


<%
'----------------------------------------------------------------------
' Please keep this declaration information when forwarding, this statement does not affect your speed!
' Copyright: All rights reserved, the source code is open, all kinds of uses are free to use, but after modification must put the modified file
' Send a copy to the author. And keep author This copyright information
'**********************************************************************
'----------------------------------------------------------------------
Dim Oupfilestream
'----------------------------------------------------------------------
' File Upload class
Class Upfile_class

Dim Form,file,version,err

Private Sub Class_Initialize
Version = "No Fear upload class Version V1.2"
ERR =-1
End Sub

Private Sub Class_Terminate
' Erase variables and the like
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 Requestbindata,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 limit size
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 ("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
Requestbindata = Oupfilestream.read
Iformend = Oupfilestream.size
Bcrlf = ChrB (+) & ChrB (10)
' Get the separator between each item
Sspace = MidB (requestbindata,1, InStrB (1,REQUESTBINDATA,BCRLF)-1)
IStart = LenB (sspace)
Iformstart = istart+2
' Explode project
Todo
Iinfoend = InStrB (Iformstart,requestbindata,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,requestbindata,sspace)-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_class
' Get file properties
Ifindstart = InStr (Ifindend,sinfo, "filename=" "", 1) +10
Ifindend = InStr (Ifindstart,sinfo, "" "", 1)
sFileName = Mid (Sinfo,ifindstart,ifindend-ifindstart)
Ofileinfo.filename = Mid (Sfilename,instrrev (sFileName, "") +1)
Ofileinfo.filepath = Left (Sfilename,instrrev (sFileName, ""))
Ofileinfo.fileext = Mid (Sfilename,instrrev (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
' 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
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
' If you get to the end of the file, quit.
Loop Until (iformstart+2) >= iformend
Requestbindata = ""
Set Tstream = Nothing
End Sub
End Class

'------------------------------------------------------------------------------
' File attribute Class
Class Fileinfo_class
Dim Formname,filename,filepath,filesize,filetype,filestart,fileext
' Save File Method
Public Function SaveToFile (Path)
If LCase (right (path,3) <>lcase (fileext)) Then ' Classic Upload vulnerability ^_^
Response. Write ("<script language=javascript>alert (' www.111cn.net: not allowed to upload this file! '); </script> ")
Response.End
End If
On Error Resume Next
Dim Ofilestream
Set Ofilestream = CreateObject ("ADODB. Stream ")
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
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.