This is a downloadable demo showing how to use the ASPFileSaver component to save uploaded files using ASP. It forms a miniature application allowing files to be uploaded, viewed and deleted. The ASPFileSaver component must be registered on the server before this demo can be run. This component and the demo files can be downloaded using the links below.
Download the demo - filesave.zip (3 KB)
Download the ASPFileSaver trial (131 KB)
The demo, filesave.zip, contains the following files. The component is not included with the demo files.
| File | Description |
|---|---|
| fileupload.htm | The starting page. This contains an HTML form for uploading a file to the server. |
| filesave.asp | The script that saves the file. This is the script that calls the ASPFileSaver component. |
| view.asp | This shows the files that have been uploaded. It uses the File System Object to do this. |
| delete.asp | This uses the File System Object to delete a previously uploaded file. |
| readme.txt | A description of the application, including some troubleshooting tips. |
Some of the important features are explained below.
This page contains a form with the input type="file" tag allowing the user to upload a file. The "enctype" attribute must be set as shown:
<form method="post" action="filesave.asp" enctype="multipart/form-data">
<input type="file" name="filesent">
<input type="submit" value="Send File">
</form>
This script uses ASPFileSaver to save the uploaded file. Its first task is to create an instance of the component:
Set Upload = Server.CreateObject("ASPFileSaverTrial.FileSave")
The rest of the script consists of an If..Then..Else statement that checks if a file has been uploaded, saves it and prints an appropriate message to the client.
If Upload.FileSize > 0 Then
Upload.SaveFile Server.MapPath("./files/") & "\" & Upload.FileName
'File saved
Else
'No file uploaded
End If
The SaveFile command requires a full physical path and in this case it is constructed using Server.MapPath.
These scripts do not use our component so we will leave the reader to view the code to see how they work. They use the File System Object to list files in a folder and to delete selected files.
© Chestysoft, 2008.