Frog Frog recommended: Frog Frog Brand no component upload class

Source: Internet
Author: User
Tags chr end gettext return string domain name
Upload | no component | upload | no components
<%
' When the table dropdowns has both a text field and a file field, we must set the form's encoding type to the ' Multipart/form-data ' type
' This time, the encoded file uploaded does not directly remove the values of the text field and the binary data of the file field, which requires splitting the form field
' There is a random separator between each form field in the uploaded data stream, the delimiter is invariant in the same stream, and the different flow delimiters are unchanged.
' This delimiter is at the very beginning of the stream and ends with a CHRB + CHRB (10), so we can use this delimiter to traverse the split form field after that.
' For file domains, we want to resolve the field name, filename, file type, and file content, the domain name is preceded by "Name=" and included in a pair of double quotes, the value of the filename is preceded by "filename=", also enclosed in double quotes, which contains the full path and filename of the file, Followed by a pair of return carriage returns (CHRB) +CHRB (10)), the string "Content-type:" and two pairs of carriage return line between the contents of the file type string, two pairs of carriage return line to the pair of carriage return line between the data for the file content
' For a text field, we just parse his value, and the name of the field is wrapped in double quotes after "Name=," and two pairs of return lines to the value of the text field between the field delimiters that start with a pair of carriage return breaks
' Of course upload the stream is binary format, in the operation of the need to use some binary function, rather than the usual operation of string functions, such as LEFTB,MIDB,INSTRB, the following is the implementation of the algorithm
Class Getpost
Private Bdatastr,separationstr,wawa_stream ' submitting information, separating characters between form fields
' Class initialization
Private Sub Class_Initialize
Set Wawa_stream=createobject ("ADODB.stream") ' Creates a global stream
Wawa_stream.mode=3 ' Read and write mode
wawa_stream.type=1 ' binary read mode
Wawa_stream.open ' Open stream
Bdatastr=request.binaryread (request.totalbytes) ' Get all the data uploaded
Wawa_stream.write bdatastr ' Read data
Separationstr=leftb (BDATASTR,CLNG (INSTRB (BDATASTR,CHRB) + ChrB (10))-1) ' delimited string
End Sub
' Class destructor, unload global stream object
Private Sub Class_Terminate
Wawa_stream.close
Set wawa_5xsoft_stream=nothing
End Sub
' Returns the value of the File Form field (binary)
Public Function GetFile (FieldName)
Dim L1,DATASTART,DATALNG
L1 = InStrB (Bdatastr,getbinary ("name=" + Chr (34) +fieldname))
Datastart = InStrB (L1,BDATASTR,CHRB) + ChrB (a) + ChrB (+ ChrB (10)) +4
DATALNG = InStrB (datastart,bdatastr,separationstr)-DataStart-2
GetFile =midb (BDATASTR,DATASTART,DATALNG)
End Function
' Returns the type of file
Public Function Getfiletype (FieldName)
Dim L1,DATASTART,DATALNG
L1 = InStrB (Bdatastr,getbinary ("name=" + Chr (34) +fieldname))
Datastart = InStrB (L1,bdatastr,getbinary ("Content-type:")) + 13
DATALNG = InStrB (DATASTART,BDATASTR,CHRB) + ChrB (a) + ChrB (a) + ChrB)-Datastart
Getfiletype =gettext (MidB (BDATASTR,DATASTART,DATALNG))
End Function
' Returns the original path of the file
Public Function GetFilePath (FieldName)
Dim L1,DATASTART,DATALNG
L1 = InStrB (Bdatastr,getbinary ("name=" + Chr (34) +fieldname))
Datastart = InStrB (L1,bdatastr,getbinary ("filename=")) + 9
DATALNG = InStrB (DATASTART,BDATASTR,CHRB (+) + ChrB)-Datastart
GetFilePath = GetText (MidB (bdatastr,datastart+1,datalng-2)) ' Remove the left and right double quotes, and don't know why the double quotes on the right side are minus 2.
End Function
' Returns the suffix name of the original file
Function Getextendname (FieldName)
FileName = GetFilePath (FieldName)
If IsNull (FileName) or filename= "" Then
Getextendname= ""
Exit Function
End If
Getextendname = Mid (Filename,instrrev (FileName, "."))
End Function
' Returns the value of the File Form field (binary)
Public Function GetFileSize (FieldName)
Dim L1,DATASTART,DATALNG
L1 = InStrB (Bdatastr,getbinary ("name=" + Chr (34) +fieldname))
Datastart = InStrB (L1,BDATASTR,CHRB) + ChrB (a) + ChrB (+ ChrB (10)) +4
DATALNG = InStrB (datastart,bdatastr,separationstr)-DataStart-2
GetFileSize = datalng
End Function
' Remove the value of the form field from the binary string (string)
Public Function Retfieldtext (FieldName)
Dim L1,DATASTART,DATALNG
L1 = InStrB (Bdatastr,getbinary ("name=" + Chr (34) +fieldname))
Datastart = InStrB (L1,BDATASTR,CHRB) + ChrB (a) + ChrB (+ ChrB (10)) +4
DATALNG = InStrB (datastart,bdatastr,separationstr)-DataStart-2
Retfieldtext =gettext (MidB (BDATASTR,DATASTART,DATALNG))
End Function
' Returns a concatenated string of time and random numbers used to build the file name
Function Getrandstr ()
Dim Rannum
Randomize
Rannum = Int (90000*rnd) +10000
Getrandstr = &month (now) &day (now) &hour (now) &minute (now) &second
End Function

' Converts the binary Outer code series into a VB string
Private Function GetText (STR1R)
Dim S,t,t1,i
s = "": t= "": t1= ""
For I =1 to LenB (STR1R)
t= AscB (MidB (str1r,i,1)) ' Out of code by byte
If not (T > 127) Then ' byte High is 0, representing English characters
s = s + Chr (t)
Else
i =



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.