Upload <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)
' Separating the length of the 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 = InStrB (FIELDNAMESTART,FORMDATA,CHRB)-Fieldnamestart ' (") the ASC value =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 = InStrB (FIELDFILENAMESTART,FORMDATA,CHRB)-Fieldfilenamestart ' (") the ASC value =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 an 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 you must keep the number of bytes 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
' Create 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)
' Judge whether the characters in Chinese
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, in turn.
If varasc<0 Then
VARASC = Varasc + 65535
End If
' Handling 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>
<sc