A Simple Upload in ASP


To allow file uploads, NTFS permissions must be set appropriately for FileUp's temporary and destination directories. The IUSR_MACHINENAME or authenticated user account must have Read, Write, and Modify access to this folder. For more information, see Setting Appropriate Security.

Here is a simple HTML form that uploads a file:

The Client Code
<html>

<head>
<title>Please Upload Your File</title>
</head>

<body>

<form enctype="multipart/form-data" method="post"
action="formresp.asp">

Enter filename to upload:
<input type="file" id="myFile" name="myFile" /><br />
<input type="submit" />

</form>
</body>
</html>

When using an HTML form to upload files, the form submitting the file must contain:

The form uploads the file to formresp.asp (specified by the <form>tag's action attribute). Formresp.asp contains the following code:

The Server Code
<%@ language="vbscript" %>
<html>

<head>
<title>Upload File Results</title>
</head>

<body>
<%
Dim fileUpload
Set fileUpload = Server.CreateObject("SoftArtisans.FileUp")

fileUpload.Path = "C:\Temp"

'--- Check to be sure there was a file selected in the form
'--- If so, continue processing
If IsObject(fileUpload.Form("myFile")) Then
If Not fileUpload.Form("myFile").IsEmpty Then

<fileUpload.SaveAs "C:\uploads\upload.out"

Response.Write "FileUp Saved the File Successfully."
Else
Response.Write "There was no file submitted in the form field."
End If
Else
Response.Write "The referenced field does not exist " & _
"or is not of type=""file"""
End If

'--- Dereference FileUp
Set fileUpload = Nothing
%>
</body>
</html>

The following lines process the upload request, and save the uploaded file


Setting the Path Property

The Path propery must be set before referencing any variables on the form. As soon as a form element is referenced, FileUp will read in the entire contents of the HTTP post, including all form elements and files. Therefore, if you set Path after referencing a form element, by the time the Pathproperty is set, all of the Form data will have been read, and the cache files created, rendering the Path assignment meaningless.

If you do not set the Path property, FileUp will cache the upload in the server's default directory for cached files.


Summary

Top

Copyright © 2010 SoftArtisans, Inc. All rights reserved.