At present, there are many upload classes without components. I have probably taken a look at it. Most of them are quite complicated to write, and some can only transmit text. The most important thing is that there are no 10 lines of code or less :), I spent one night studying ADODB. stream, and six lines of code are used to implement the upload without components:
Upload. asp file code
<%
Strfilename = request. querystring ("FN ")
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. type = 1 'adtypebinary binary method
Objstream. Open
Objstream. loadfromfile strfilename
Objstream. savetofile server. mappath ("zslogo.gif"), 2
%>
Usage
Enter:
Http: // xxx/upload. asp? Fn = C:/upload a file/123.gif
XXX is your website domain name address, for example, www.jzxue.com.
After the execution, you will see an extra zslogo.gif under your directory, which is the file you just uploaded!
Based on the principle of ASP Component-less upload, we can extend the above Code to the following code:
Upload. asp file code
<%
Function getfilename (byval FN)
If FN <> "" Then getfilename = mid (FN, limit Rev (FN, "/") + 1) else getfilename = ""
Endfunction
Strfilename = request. Form ("file1 ")
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. type = 1 'adtypebinary
Objstream. Open
Objstream. loadfromfile strfilename
Objstream. savetofile server. mappath (getfilename (strfilename), 2
Objstream. Close
%>
Upload.htm File Code
<Form name = "upform" Action = "Upload. asp" method = "Post" enctype = "multipart/form-Data">
<Input type = "file" name = "file1" style = "width: 400px;" value = ""/>
<Input type = "Submit" name = "Submit" value = "Upload File"/>
</Form>