How to integrate the file upload function in a Web page

Source: Internet
Author: User
Tags command line empty file upload ftp servervariables ftp client hosting server hosting
Currently, personal homepage making is very popular. When users develop their own pages, need to transfer files to the server, one way to solve this problem
is to run the FTP server and set the FTP default directory for each user to the user's Web home directory, so that the user can run the FTP client and upload files to the specified
Web directory. Since neither Windows NT nor Windows98 provides a direct windows-based FTP client, users must know how to use command line based
FTP client, or master a new FTP client based on the Windows Form. Therefore, this solution is only feasible for experienced users who are familiar with FTP
Of If we can integrate the file upload function with the web, so that users can complete the upload task with only a Web browser, this will be very convenient for them.
The following is a brief introduction to this scheme based on the author's practical experience.
The software configuration of the scheme is as follows: The client operating system is WINDOWS98; The server operating system is a Windows NT server;web server
IIS4.0. To enable IIS to receive uploaded files, you must also install the Posting Acceptor component located at the NT 4.0 Option Pack Site
In the Server Express. Posting Acceptor Component ISAPI extension function CPSHOST.DLL directly process file upload, destination URL is mapped, resolved to service
The physical disk location on the device.
Specific application see the following page code:



<% Response.Buffer = TRUE%>
<% if (Len request.servervariables ("logon_user") = 0) then%>
<% Response.Status = "401 Unauthorized"%>
<HTML><BODY><B> Error: Denying access to .</b><p></body><% Else%>
<title> Upload file </title>
<body>

&LT;H1 align= "center" > Upload file
<form method= "POST" enctype= "Multipart/form-data"
Action= "http://<%= request.servervariables (" SERVER_NAME ")%>
/myweb/cpshost.dll? PUBLISH ">
<input name= "TargetUrl" type= hidden "value=" http://<%=
Request.ServerVariables ("SERVER_NAME")%>/myweb/<%=
Request.ServerVariables ("Logon_User")%> "
>
Please select the file to upload: <input name= "My_file" type= "file" ><br>
Please select the file to upload: <input name= "My_file" type= "file" ><br>
Please select the file to upload: <input name= "My_file" type= "file" ><br>
<br>
<input type= "Submit" Name= "Cmdup" value= "Upload" >
</form>
</body>
<% End If%>



The above code is stored in the form of an ASP file in the MyWeb directory under the Web site hosting directory, and the user simply requests the file in a browser.
The points to be noted are:
⒈request.servervariables ("LOGON_USER") returns the name of the user logged on to the Windows NT domain, in this case, if the user name is empty, display
The page is denied access and is not empty to display the normal upload page.
⒉ after the Posting Acceptor component is installed, Cpshost. The DLL file is located in the scripts directory under the Web server hosting directory, and you can copy the file to the
Use in your own directory.
⒊ in the form, enctype= "Multipart/form-data" This item can not be less, otherwise can not normal upload.
The name (Name property) of the ⒋ form control targeturl cannot be changed. Type= "Hidden" makes the control not appear on the page. The Value property determines whether the upload file
The path stored in the server can be adjusted according to the actual situation. In this case, the file upload path is the MyWeb directory (that is, this ASP file and the CPSHOST.DLL text
directory) under a subdirectory with the same name as the logged-on user name, and the directory permissions are set to writable.
The ⒌my_file control type is "file" and the browser displays a text box with a "Browse" button. When the user clicks the Browse button, it bounces
A standard Selection file dialog box for the user to select the file to upload. You can increase or decrease the number of My_file controls according to your actual needs.


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.