Converts a binary character to a normal character (Multipart/form-data out)

Source: Internet
Author: User
Tags exit chr strlen
form-data|multipart| Binary | Conversion <%
Response.expires=0
' Purpose: Converts binary characters to normal characters
Function Bin2str (BINSTR)
Dim Varlen,clow,ccc,skipflag
Skipflag=0
CCC = ""
Varlen=lenb (BINSTR)
For I=1 to Varlen
If skipflag=0 Then
Clow = MidB (binstr,i,1)
If AscB (Clow) > 127 Then
CCC =CCC & Chr (AscW (MidB (binstr,i+1,1) & Clow))
Skipflag=1
Else
CCC = CCC & Chr (AscB (Clow))
End If
Else
Skipflag=0
End If
Next
BIN2STR = CCC
End Function
' Objective: To separate the image data from the form
' Where the parameter formsize is the form data size, Formdata is the total data for the form
Function Imageup (Formsize,formdata)
BNCRLF=CHRB (+) & ChrB (10)
Divider=leftb (FORMDATA,INSTRB (FORMDATA,BNCRLF)-1) ' Formdata the data on the left of the first Bncrlf
DATASTART=INSTRB (Formdata,bncrlf & Bncrlf) +4 ' two Bncrlf the starting bit of the right data
DATAEND=INSTRB (Datastart+1,formdata,divider)-datastart
IMAGEUP=MIDB (Formdata,datastart,dataend)
End Function
' Purpose: To remove the value of a variable from a form
' Where the parameter varname is the field variable to look for, strtxt all text that has been detached from the image
Function Findvar (Varname,strtxt)
Startpos=1
Strlen=len (VarName) +2
' There may be multiple variables with the same name in the form (used in the data update with the main table and the BOM)
For I=1 to Len (strtxt)
Varstart=instr (Startpos,strtxt,varname) +strlen+3
Varend=instr (Varstart,strtxt, "--")-2
Varvallen=varend-varstart

Invar=mid (Strtxt,varstart,varvallen)
Findvar=findvar & Invar

Startpos=instr (Varstart,strtxt,varname)
If Startpos=0 then exit for ' if not found then exit loop
Findvar=findvar & "," "," as a separator between multiple values of the same name, in fact, this example does not require
Next
End Function

Formsize = Request.TotalBytes
FormData = Request.BinaryRead (formsize)
Image = Imageup (formsize,formdata)
' The following two steps cannot be omitted, otherwise the text can not be taken out
Strtxt=mid (Formdata,instr (formdata,image) +len (image) +1) ' Take out text
Strtxt=bin2str (strtxt) ' binary conversion to normal text

Aaa=findvar ("AAA", Strtxt) ' equivalent to Request.Form ("AAA")
%>


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.