Note: Part of the collected part from the Internet and written some. The main upgrade is a class package for Form's binary data, which can be easily obtained from the information of the elements within the Form.
FORM binary data format:
Split marker data 0x0d
0A
Element Description Information 0x0D
0D
Element content data 0x0d
Element content data 0x0D
......
1. UPLOAD.HTM
form>
body>
html>
2. Upload.asp
<%
'by Sam 2004, 6
'######################################################## ####
Response.expires = 0
If Request.servervariables ("Request_Method") = "post" then
Response.clear ()
Response.buffer = TRUE
Set uform = New UploadForm
uform.find_element "text0"
Data = MIDB (uform.formdata, uform.datast, uform.datalen)
Response.binaryWrite Data
SDATA = BinaryTostring (DATA)
Response.write SDATA
Response.binaryWrite StringTobinary (SDATA)
uform.find_element "file1"
Savefile server.mappath ("/ recv1.dat"), uform.formdata, uform.datastart, uform.Datalen
uform.find_element "file2"
Savefile server.mappath ("/ recv2.dat"), uform.formdata, uform.datastart, uform.datalen
SET uform = Nothing
END IF
%>
3. UPLOAD.INC <%
'#########################################################
Function Savefile (FileName, Formdata, Start, Len)
SET STRM1 = Server.createObject ("adodb.stream")
SET STRM2 = Server.createObject ("AdoDb.Stream")
Strm1.open
Strm1.type = 1 'binary
Strm2.open
Strm2.type = 1 'binary
Strm1.write Formdata
'strm1.savetofile server.mappath ("/ 1.RAW"), 2
Strm1.position = start - 1
Strm1.couthto strm2, len
'strm2.savetofile server.mappath ("/ 1.gif"), 2
Strm2.savetofile filename, 2
SET STRM1 = Nothing
SET STRM2 = Nothing
END FUNCTION
Function SimpleBinaryToString (binary)
DIM I, S
For i = 1 to lenb (binary)
S = S & CHR (ASCB (MIDB (Binary, I, 1))))))
NEXT
SimpleBinaryToString = S
Function binarytostring (binary)
DIM CL1, CL2, CL3, PL1, PL2, PL3
Diml
CL1 = 1
CL2 = 1
CL3 = 1
l = lenb (binary)
Do While CL1 <= L
PL3 = PL3 & CHR (ASCB (MIDB (Binary, CL1, 1))))
CL1 = CL1 1
CL3 = CL3 1
IF CL3> 300 THEN
PL2 = PL2 & PL3
PL3 = ""
CL2 = CL2 1
IF CL2> 200 THEN
PL1 = PL1 & PL2
PL2 = ""
loop
BinaryToString = PL1 & PL2 & PL3
Function StringTobinary (String)
DIM I, B
For i = 1 to len (string)
B = B & ChRB (ASC (MID (String, I, 1))))
StringTobinary = B
Class UploadForm
Private sub coplass_initialize ()
DataStart = 0
Datalen = 0
Formsize = Request.totalbytes
Formdata = Request.binaryRead (Formsize)
'response.write " Myclass Start "
End Sub
Private sub coplass_terminate ()
'response.write " Myclass over " End Sub
Public DataStart
Public Datalen
Public Formsize
Public Formdata
Public Sub Find_Element (Name)
Bncrlf = chrb (13) & chrb (10)
Strname = "name =" & chr (34) & name & chr (34)
SPOS = 1
EPOS = 1
K = 0
Do While (Spos EPOS = INSTRB (SPOS, FORMDATA, BNCRLF) Divider = MIDB (Formdata, Spos, EPOS - SPOS) SDIVIDER = BinaryToString (Divider) 'Response.write SDIVIDER & "" 'response.binarywrite divider & "" SPOS = EPOS 2 EPOS = INSTRB (Spos, Formdata, Bncrlf & Bncrlf) Header = MIDB (Formdata, SPOS, EPOS - SPOS) Sheader = binarytostring (header) 'Response.write Sheader & "" 'response.binarywrite header & "" Spos = EPOS 4 EPOS = INSTRB (SPOS, FORMDATA, DIVIDER) IF INSTR (SHEADER, STRNAME> 0 THEN DataStart = SPOS 'base 1 Datalen = EPOS - SPOS - 2 'response.write "start =" & datastart & "" 'response.write "end =" & datalenten & "" 'Savefile Server.mappath ("/ Output.dat"), Formdata, Datastart, Datalen Exit do END IF Spos = EPOS K = K 1 IF (k> 20) THEN Exit do END IF loop End Sub END CLASS %> Sam SHA Sam_sha@sina.com.cn 2004-6-7
EPOS = INSTRB (SPOS, FORMDATA, BNCRLF)
Divider = MIDB (Formdata, Spos, EPOS - SPOS)
SDIVIDER = BinaryToString (Divider)
'Response.write SDIVIDER & ""
'response.binarywrite divider & ""
SPOS = EPOS 2
EPOS = INSTRB (Spos, Formdata, Bncrlf & Bncrlf)
Header = MIDB (Formdata, SPOS, EPOS - SPOS)
Sheader = binarytostring (header)
'Response.write Sheader & ""
'response.binarywrite header & ""
Spos = EPOS 4
EPOS = INSTRB (SPOS, FORMDATA, DIVIDER)
IF INSTR (SHEADER, STRNAME> 0 THEN
DataStart = SPOS 'base 1
Datalen = EPOS - SPOS - 2
'response.write "start =" & datastart & ""
'response.write "end =" & datalenten & ""
'Savefile Server.mappath ("/ Output.dat"), Formdata, Datastart, Datalen
Exit do
Spos = EPOS
K = K 1
IF (k> 20) THEN
END CLASS
Sam SHA
Sam_sha@sina.com.cn
2004-6-7