ASP No component Upload

Source: Internet
Author: User
Upload | No component ASP no component upload



Description: Collect a part from the Internet and write it yourself. The main promotion is the form of binary data for the class encapsulation, you can easily get the information of the elements within the form.



Form binary Data format:



Split Flag Data + 0x0d0a

Element description Information + 0x0d0a0d0a

Element content Data + 0x0d0a



Split Flag Data + 0x0d0a

Element description Information + 0x0d0a0d0a

Element content Data + 0x0d0a



......



Split Flag Data + 0x0d0a





1. Upload.htm





<body>

<form enctype= "Multipart/form-data" action= "upload.asp" method= "POST" >

<input name= "text0" type=text value= "text box" ><br>

<input name= "file1" Type=file accept= "image/*" ><br>

<input name= "file2" Type=file accept= "image/*" ><br>

<input type=submit value= "Upload" >

</form>

</body>




2. upload.asp

<!--#include file= "Upload.inc"-->

<%

' 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.datastart,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

<%

' By Sam 2004,6

'#################################################################

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.copyto 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

End Function



function binarytostring (binary)

Dim cl1,cl2,cl3,pl1,pl2,pl3

Dim l

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 = ""

Cl3 = 1

Cl2 = Cl2 + 1

If cl2>200 Then

PL1 = PL1 & PL2

PL2 = ""

Cl2 = 1

End If

End If

Loop

binarytostring = pl1 & pl2 & PL3

End Function






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.