6 lines of code to implement ASP no component upload

Source: Internet
Author: User

There are a lot of non-component upload class, I probably looked at a bit, most of the writing is quite complex, some incredibly still can only pass text, the most critical is not 10 lines of code below:), I spent a night to study the ADODB.stream, and 6 lines of code to implement the component-free upload:
Upload.asp file Code
<%
strFileName = Request.QueryString ("FN")
Set objstream = Server.CreateObject ("ADODB. Stream ")
objStream.Type = 1 ' adtypebinary binary mode
objStream.Open
objStream.LoadFromFile strFileName
Objstream.savetofile Server.MapPath ("Zslogo.gif"), 2
%>
Use the method
in the browser input:
Http://xxx/upload.asp?fn=c :/upload file/123.gif
where xxx is your website domain address, such as: Www.jzxue.com
After you have finished executing you will see a zslogo.gif under your directory, that is, you just uploaded the file pull.
based on ASP's no-component upload principle, we extend the above code to the following code:
upload.asp File code
<%
Function getfilename (ByVal fn)
If fn<> "" Then Getfilename=mid (Fn,instrrev (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>

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.