Copy codeThe Code is as follows: <input name = "file" type = "file">
Formsize = request. totalbytes
Formdata = request. binaryread (formsize)
Bncrlf = chrB (13) & chrB (10)
Divider = leftB (formdata, clng (partition B (formdata, bncrlf)-1)
Datastart = instrb (formdata, bncrlf & bncrlf) + 4
Dataend = Consumer B (datastart + 1, formdata, divider)-datastart
Mydata = midb (formdata, datastart, dataend)
Formsize = request. totalbytes
Obtains the maximum number of bytes for upload.
-----------------------
Formdata = request. binaryread (formsize)
Get form data of binary stream
-----------------------
Bncrlf = chrB (13) & chrB (10)
Set the crlf carriage return line code variable
------------------------------
Divider = leftB (formdata, clng (partition B (formdata, bncrlf)-1)
Obtain the byte data on the left of the first crlf.
When B (formdata, bncrlf)-1 checks to find that the bit value of the crlf binary byte is reduced by one, that is, the binary data before the flag bit information. It must be noted that when B returns clng, therefore, adding a clng here is redundant.
------------------------------
Datastart = instrb (formdata, bncrlf & bncrlf) + 4
Obtain the image data and remove the start position of the header information added to the form, that is, your type = file starts from the byte position of the real file data after the form is submitted.
The position of two consecutive crlf + 4 (that is, the length of a crlfg)
-------------------------------
Dataend = Consumer B (datastart + 1, formdata, divider)-datastart
The position of the obtained data + 1 is used as the reference calculation value for checking the end of the data. The first binary form separator header information is returned at the position starting with datastart + 1, subtract the relative location of datastar.
----------------------------
Mydata = midb (formdata, datastart, dataend)
Midb () obtains the star end-bit data of the uploaded file data obtained after multiple twists and turns.
OK --------------> the uploaded second-level data is extracted cleanly.
Note:
(1). All * B series VB functions are processed by byte. They must be used to process the second-level system.
(2). type = file and form data of the corresponding form type are appended with the corresponding header information for each file field after submission.
Therefore, you must use the above algorithm to clearly find the real file data.
(3) At the same time, the header information also contains the data uploaded to the initial file name, such as c: \ aaa \ aaa.jpg. You can also process formdata and extract the initial file name of the data in this file domain.
(4) These algorithms are derived from the format data provided by the http "form" Specification, so any processing algorithm is similar!