ASP file Upload (AspUpload component upload)

Source: Internet
Author: User
Tags truncated

To implement this feature, you need to use some specially crafted file upload components. There are a lot of pages on the file upload component, here are some of the most famous AspUpload components in the world.

1 Download and install AspUpload
To implement this feature, you need to use some specially crafted file upload components. The File Upload Component page is very numerous, here is the international very famous AspUpload component, its download URL is:
Http://www.persits.com/aspupload.exe
The component provider URL is:
Http://www.aspupload.com
Note: First remove the read-only attribute of the folder where you want to store the uploaded files, and for Windows2000 and Windows XP, if you are installing with the NTFS file system, you will also need to set the folder to everyone (anyone) to have full control.
After downloading the component according to the above URL, directly double-click the download file, follow the prompts step by step installation. After installation, the "C:\Program files\persits software\aspupload" folder will be generated by default, with instructions and examples.

2. Uploading files using the AspUpload component
This component is powerful and can not only upload files, but also upload some form element values like normal forms, so that you can add some explanatory text to the uploaded files. Because both the upload file attributes and upload form properties, it is more complex, here only the most commonly used.
The common properties of the upload component are shown in table 8-2.
Table 8-2 Properties of the upload component


The common methods for uploading components are shown in table 8-3.
Table 8-3 Methods for uploading components

The properties for uploading form elements are shown in table 8-5.
Table 8-5 properties for uploading form elements

Listing 8-3 8-3.asp uploading a file form
< head>
< title> upload a file example </title>
< body>
< H2 align= "center" > Upload a file </H2>
< center>
< form action= "8-4.asp" method= "post" enctype= "Multipart/form-data" >
Select File: <input type= "file" Name= "Upfile" ><br>
File Description: <input type= "text" name= "Intro" size= "><br>
Author name: <input type= "text" name= "author" size= "><br>
< input type= "submit" value= "OK" >
</form>
</center>
</body>
Listing 8-4 8-4.asp uploading a file execution program
<% Option Explicit%>
< html>
< head>
< title> upload a file example </title>
< body>
< H2 align= "center" > file is securely uploaded </H2>
< center>
<%
Dim Upload ' declares a variable
Set Upload = Server.CreateObject ("Persits.upload.1") ' Creates a file Upload component instance
Upload.setmaxsize 2*1024*1024,false ' limit file not exceeding 2M, otherwise truncated
Upload.overwritefiles=true ' True indicates that you can overwrite
Upload.Save "C:\inetpub\wwwroot\asptemp\chapter8\upload" ' upload to the specified folder
Response.Write "Upload file as:" &upload.files ("Upfile"). Path & "<BR>"
Response.Write "File Size:" & Upload.files ("Upfile"). Size & "Bytes <BR>"
Response.Write "File description is:" &upload.form ("Intro"). Value & "<BR>"
Response.Write "Author name:" & Upload.form ("Author"). Value & "<BR>"
%>
</center>
</body>
Program Description:
1) Note the form in the 8-3.asp form: <form action= "8-4.asp" method= "post" enctype= "Multipart/form-data"; it must be written in enctype= " Multipart/form-data ".
2) Also note that the select file with the form form of the Select File element: <input type= "file" name= "Upfile" >
3) about restricting file size, Upload.setmaxsize 2*1024*1024,false indicates that a limit file size of 2mb;false indicates that if the file exceeds 2MB, it is automatically truncated to 2MB size, and if true, does not automatically truncate. The program will report an error message.
4) about the file can be overwritten, upload.overwritefiles=true means that if the file name and the original filename is the same, it can be overwritten; false means that it cannot be overwritten, and will automatically save another name. The default is true.
5) about the file save path, Upload.Save "C:\inetpub\wwwroot\asptemp\chapter11\upload", the physical path written here, can also take advantage of the previously learned server object MapPath method, This sentence can be written as: Upload.Save.Server.Mappath ("Upload"). In this way, the procedure is easier to transplant.
6) Also note that the folder used to save the uploaded file must be present, and if the server is a Windows 2000 or Windows NT operating system, the folder permissions must be set to everyone's access, or the file will not be uploaded.
7) upload.files ("Upfile") is used to obtain the properties of the uploaded file. Path and Upload.files ("Upfile"). Size, followed by the path and size property can not be omitted, otherwise it is unclear what you want to get the properties of the file. When a form element is obtained, Upload.form ("Intro") is used. Value, at which point the Value property can be omitted.
In the example above, only one file can be uploaded at a time, if you want to upload more than one file page at a time, as long as you add multiple form elements in the normal form form, please refer to the specific examples below.
Listing 8-5 8-5.asp uploading multiple file forms
< head>
< title> upload Multiple files example </title>
< body>
< H2 align= "center" > Uploading Multiple Files </H2>
< center>
< form action= "8-6.asp" method= "post" enctype= "Multipart/form-data" >
Select File 1:<input type= "file" name= "Upfile1" >
Document Description 1:<input type=text name= "Intro1" size= "><BR>
Select File 2:<input type= "file" name= "Upfile2" >
Document Description 2:<input type=text name= "Intro2" size= "><BR>
< input type= "submit" value= "OK" >
</form>
</center>
</body>
Listing 8-6 8-6.asp uploading multiple file execution files
<% Option Explicit%>
< html>
< head>
< title> upload Multiple files example </title>
< body>
< H2 align= "center" > file is securely uploaded </H2>
< center>
<%
Dim Upload
Set Upload = Server.CreateObject ("Persits.upload.1")
Upload.Save Server.MapPath ("Upload") ' upload to the specified folder
Dim Upfile,item
For every upfile in Upload.files ' Here is a loop that writes out all the file information
Response.Write Upfile. Name & "=" & Upfile. Path & "(" & Upfile. Size & ") <BR>"
Next
For every Item in Upload.form ' Here is a loop that writes out all the form element information
Response.Write Item.name & "=" & Item.value & "<BR>"
Next
%>
</center>
</body>
Program Description:
In the above program is not the same as the previous example to write the upload file and file description, but with a For Each loop, the effect is the same. Because after uploading, actually is to pass up a Files collection, a form collection. The Files collection includes all uploaded files, and the form collection includes all upload form elements.

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.