Pure ASP separates binary files and text data from form data

Source: Internet
Author: User
Tags array exit
Binary | Data The following source code is a file

<%
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Author: playxp,email:playxp@sohu.com have questions please contact me
' function: Pure ASP separates binary files and text data in form data (supporting Chinese).
' How to: Include this file in the ASP file that processes the form, using GetValue (name) to read the values of each element in the form.
' NOTE: You must not use Request.Form to read data.
' In a large number of support ASP's home page space can only use limited components, can not use the upload component, and the built-in request object is not
' Supports reading binary files, so using this file can solve the problem of uploading files, but it is a significant performance compromise. This program refers to some of the online code.

' Convert from GBK to Unicode
Function Gbtou (Binstr,bytenum)
Gbtou= ""
For J=1 to Bytenum
GBCODE1=ASCB (MidB (binstr,j,1))
If gbcode1>&h80 Then
GBCODE2=ASCB (MidB (binstr,j+1,1))
a=gbcode1-&h81
B=gbcode2-&h40
If gbcode2>&h7f Then b=b-1
Gbtou=gbtou & ChrW (gb2u (a*190+b)) ' Gb2u for conversion tables
J=j+1
Else
Gbtou=gbtou & ChrW (AscB (MidB (binstr,j,1))
End If
Next
End Function

' Get the boundary string
Boundary=mid (Request.ServerVariables ("Content_Type"), 31)
' Number of bytes of data in form
Bytecount=request.totalbytes
' Binary data in form
Binread=request.binaryread (ByteCount)
' Border ASCII string
ENDSTR=CHRB (&AMP;CHRB) &AMP;CHRB &AMP;CHRB (45)
For I=1 to Len (boundary)
ENDSTR=ENDSTR&AMP;CHRB (AscB) (Mid (boundary,i,1))
Next

Dim Formvalue (31,3)
Dim Bytei ' byte pointer
E=0
Bytei=37+len (boundary) ' first element data at the beginning
Do While Bytei<bytecount
If AscB (MidB (binread,bytei,1)) =110 Then ' element data exists
Formvalue (e,0) = ""
Formvalue (e,1) = ""
Formvalue (e,2) = ""
Formvalue (e,3) = ""
Bytei=bytei+6 ' name begins at
Namestart=bytei
BYTEI=INSTRB (BYTEI,BINREAD,CHRB (34)) ' At the end of the name
Namelen=bytei-namestart ' name length
Formvalue (e,0) =gbtou (MidB (Binread,namestart,namelen), Namelen) ' read into the name
If AscB (MidB (binread,bytei+1,1)) =13 Then ' element is text
Bytei=bytei+5 ' text data at the beginning
Datastart=bytei
BYTEI=INSTRB (bytei,binread,endstr) ' text data at the end of
Datalen=bytei-datastart ' Text data length
Formvalue (e,1) =gbtou (MidB (Binread,datastart,datalen), datalen) ' Read text data
Else ' element as file
Bytei=bytei+13 ' path at the beginning
Pathstart=bytei
BYTEI=INSTRB (BYTEI,BINREAD,CHRB (34)) ' At the end of the path
Pathlen=bytei-pathstart
Formvalue (e,2) =gbtou (MidB (Binread,pathstart,pathlen), PathLen) ' Read-in Path
Bytei=bytei+17 ' file type start
Typestart=bytei
BYTEI=INSTRB (BYTEI,BINREAD,CHRB (13)) ' End of file type
Typelen=bytei-typestart ' File type length
Formvalue (e,3) =gbtou (MidB (Binread,typestart,typelen), Typelen) ' Read file type
Bytei=bytei+4 ' file data at the beginning
Datastart=bytei
BYTEI=INSTRB (BYTEI,BINREAD,ENDSTR) ' file data at the end of
Datalen=bytei-datastart ' File data length
Formvalue (e,1) =midb (binread,datastart,datalen) ' Read file data
End If
Bytei=bytei+38+len (boundary) ' moves the next element data at the beginning
E=e+1
Else
Exit do
End If
Loop

' Retrieving element data based on element name
' If a FORM element returns its value directly to the text data
' If the form element is a binary data file, it returns an array of 13 elements, the first element being the binary data of the file,
' The second element is the path to the file, and the third is the file type.
Function GetValue (name)
For I=0 to 31
If StrComp (Formvalue (i,0), name,1) =0 Then
If Formvalue (i,3) = "" Then
Getvalue=formvalue (i,1)
Else
Getvalue=array (Formvalue (i,1), Formvalue (i,2), Formvalue (i,3))
End If
Exit Function
End If
Next
Getvalue=null
End Function
%>




Related Article

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.