Using the ASPUpload Component.

This ASPUpload script will show you how to use the ASPUpload component to upload files with a form to your website.

Set Upload = Server.CreateObject("Persits.Upload.1")
This line creates the ASPUpload object.

Upload.IgnoreNoPost = True
This line allows us to use the HTML form and the upload code in the same script.

Upload.SetMaxSize 10000000, True
This line sets the maximum upload size for the files, specified in bytes.

On Error Resume Next
Keep executing the script if there is an error.

Count = Upload.Save("c:websitesyourfullpath")
This specifies the full path to the directory to save the uploaded files in. Count gets set to the number of files that were uploaded.

If Err.Number = 8 Then
Checks if a "file too large" error occurred and prints out a message.

Else
If Err <> 0 Then

Checks if a different error occurred and if so displays it.

Else
If Count > 0 Then

If there were no errors, displays the number of files uploaded.

The rest of the script is HTML for the upload form.

--Here is the full script, the filename should be: aspupload.asp--

<HTML>
<BODY BGCOLOR="#FFFFFF">
<%

'Easy CGI test script for ASPUpload

Set Upload = Server.CreateObject("Persits.Upload.1")

Upload.IgnoreNoPost = True

' Limit file size to 10 MB, throw an exception if file is larger
Upload.SetMaxSize 10000000, True

' Intercept all exceptions to display user-friendly error
On Error Resume Next

' Perform upload
Count = Upload.Save("c:websitesyourfullpath")

' 8 is the number of "File too large" exception
If Err.Number = 8 Then
Response.Write "Your file is too large. Please try again."
Else
If Err <> 0 Then
Response.Write "An error occurred: " & Err.Description
Else
If Count > 0 Then
Response.Write Count & " file(s) uploaded."
End If
End If
End If

%>
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="aspupload.asp">
File 1:<INPUT TYPE=FILE NAME="FILE1">
File 2:<INPUT TYPE=FILE NAME="FILE2">
<INPUT TYPE=SUBMIT VALUE="submit">
</FORM>

</BODY>
</HTML>

--End Script--

More detailed examples of the ASPUpload Component can be found at: http://www.aspupload.com

<< Back

 
 
 
Copyright © 2004 Creative Brain   || Home | Digital Photo Album | Online Store | Template Depot | Career | Help & Support | Contact Us