Multiple forms and multiple pictures upload the perfect solution

Source: Internet
Author: User
Tags chr
Solve | upload upload.inc
<!--------------------->
<script Runat=server language=vbscript>
Function Getupload (FormData)
Dim Datastart,divstr,divlen,datasize,formfielddata
"Delimited sign string (+CRLF)
Divstr = LeftB (FORMDATA,INSTRB (Formdata,str2bin (VbCrLf)) + 1)
"The length of the delimited sign string
Divlen = LenB (DIVSTR)
Posopenboundary = InStrB (FORMDATA,DIVSTR)
Poscloseboundary = InStrB (posopenboundary + 1,formdata,divstr)
Set Fields = CreateObject ("Scripting.Dictionary")

While Posopenboundary > 0 and poscloseboundary > 0
' Name start position (name= "xxxxx"), plus 6 because [name=] length is 6
Fieldnamestart = InStrB (Posopenboundary,formdata,str2bin ("name=")) + 6
Fieldnamesize = ASC value of InStrB (FIELDNAMESTART,FORMDATA,CHRB)-Fieldnamestart ' (") =34
Formfieldname = Bin2str (MidB (formdata,fieldnamestart,fieldnamesize))

' FileName starting position (filename= "xxxxx")
Fieldfilenamestart = InStrB (Posopenboundary,formdata,str2bin ("filename=")) + 10
If Fieldfilenamestart < poscloseboundary and Fieldfilenamestart > Posopenboundary Then
Fieldfilenamesize = ASC value of InStrB (FIELDFILENAMESTART,FORMDATA,CHRB)-Fieldfilenamestart ' (") =34
Formfilename = Bin2str (MidB (formdata,fieldfilenamestart,fieldfilenamesize))
Else
Formfilename = ""
End If

' Content-type starting position (CONTENT-TYPE:XXXXX)
Fieldfilectstart = InStrB (Posopenboundary,formdata,str2bin ("Content-type:")) + 14
If Fieldfilectstart < poscloseboundary and Fieldfilectstart > Posopenboundary Then
Fieldfilectsize = InStrB (Fieldfilectstart,formdata,str2bin (VbCrLf & VbCrLf))-Fieldfilectstart
Formfilect = Bin2str (MidB (formdata,fieldfilectstart,fieldfilectsize))
Else
Formfilect = ""
End If

' Data start position: 2 CRLF Start
Datastart = InStrB (Posopenboundary,formdata,str2bin (VbCrLf & VbCrLf)) + 4
If formfilename <> "" Then
' Data length, minus 1 because of the number of bytes accessed by the data file (may be a problem with the AppendChunk method):
"Because an odd number of bytes of image is saved to the database, the last character is removed, causing the image to display incorrectly.
This problem does not occur with a data file with an even number of bytes, so the number of bytes must be kept even.
DataSize = InStrB (datastart,formdata,divstr)-DataStart-1
Formfielddata = MidB (formdata,datastart,datasize)
Else
' Data length, minus 2 because there is a CRLF in front of the separator flag string
DataSize = InStrB (datastart,formdata,divstr)-DataStart-2
Formfielddata = Bin2str (MidB (formdata,datastart,datasize))
End If

"Set up a dictionary set to store the relevant data for each field in the form
Set Field = Createuploadfield ()
Field.name = Formfieldname
Field.filepath = Formfilename
Field.filename = GetFileName (formfilename)
Field.contenttype = Formfilect
Field.length = LenB (formfielddata)
Field.value = Formfielddata

Fields.Add Formfieldname, Field

Posopenboundary = Poscloseboundary
Poscloseboundary = InStrB (posopenboundary + 1,formdata,divstr)
Wend
Set getupload = Fields
End Function

"Converts a binary string to a normal string function
Function Bin2str (BINSTR)
Dim Varlen,clow,ccc,skipflag
' Chinese character skip flag
Skipflag=0
CCC = ""
If not IsNull (BINSTR) Then
Varlen=lenb (BINSTR)
For I=1 to Varlen
If skipflag=0 Then
Clow = MidB (binstr,i,1)
"To determine whether Chinese characters
If AscB (Clow) > 127 Then
"ASCW will reverse the high and low of the binary Chinese double-byte characters, so we must first invert the Chinese level
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
End If
BIN2STR = CCC
End Function


"Convert a normal string into a binary string function
Function Str2bin (VARSTR)
Str2bin= ""
For I=1 to Len (VARSTR)
Varchar=mid (varstr,i,1)
VARASC = ASC (varchar)
The ' ASC ' value for Chinese characters may be negative,
"Plus 65536 to find out its unsigned value
'-1 is 0xffff in the machine with the complement,
' Its unsigned value is 65535,65535=-1+65536
' Other negative numbers, and so on.
If varasc<0 Then
VARASC = Varasc + 65535
End If
"Processing of Chinese: separating double-byte lows and highs
If varasc>255 Then
Varlow = Left (Hex (ASC (varchar)), 2)
Varhigh = Right (Hex (ASC (varchar)), 2)
Str2bin = Str2bin & ChrB ("&h" & Varlow) & ChrB ("&h" & Varhigh)
Else
Str2bin = Str2bin & ChrB (AscB (varchar))
End If
Next
End Function

' Get filename (remove path)
Function GetFileName (FullPath)
If fullpath <> "" Then
FullPath = StrReverse (FullPath)
FullPath = Left (FullPath, InStr (1, FullPath, "\")-1)
GetFileName = StrReverse (FullPath)
Else
GetFileName = ""
End If
End Function
</SCRIPT>
<script Runat=server language=jscript>
function Createuploadfield () {return n



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.