Due to the "multipart/form-data" attribute of upload forms,
your ASP script can no longer use the built-in Request.Form collection
to access individual form items.
AspUpload solves this problem by offering two collections of its own, Upload.Files
and Upload.Form to provide access to uploaded files
and text fields, respectively.
Upload.Files is a collection of UploadedFile
objects which offer access to various properties and attributes of uploaded files,
such as filename, path, size, hash value, etc. The UploadedFile object also offers
many methods which enable you to manipulate uploaded files (copy, move, save to the database,
delete, etc.) Individual items of the collection can be referenced
via numeric or string indices, or iterated through via the For-Each statement.
Upload.Form is a collection of FormItem
objects that represent text fields on an upload form. Upload.Form is similar
to Request.Form and should be used instead of the latter in your upload script.
The FormItem object provides two properties, Name and Value.
The use of the Files and Form collections is demonstrated by the sample files
Form2.asp and UploadScript2.asp:
<HTML>
<BODY BGCOLOR="#FFFFFF">
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="UploadScript2.asp">
File 1:<INPUT TYPE=FILE NAME="FILE1">
Description 1:<INPUT TYPE=TEXT NAME="DESCR1"><BR>
File 2:<INPUT TYPE=FILE NAME="FILE2">
Description 2:<INPUT TYPE=TEXT NAME="DESCR2"><BR>
<INPUT TYPE=SUBMIT VALUE="Upload!">
</FORM>
</BODY>
</HTML>
|
This form contains both <INPUT TYPE=FILE> and regular <INPUT TYPE=TEXT> items.
It invokes the script UploadScript2.asp:
<HTML>
<BODY>
<%
Set Upload = Server.CreateObject("Persits.Upload.1")
Upload.Save "c:\upload"
%>
Files:<BR>
<%
For Each File in Upload.Files
Response.Write File.Name & "= " & File.Path & " (" & File.Size &" bytes)<BR>"
Next
%>
<P>
Other items:<BR>
<%
For Each Item in Upload.Form
Response.Write Item.Name & "= " & Item.Value & "<BR>"
Next
%>
</BODY>
</HTML>
|
Click the link below to run this code sample:
http://localhost/aspupload/02_simple/Form2.asp
The output should look similar to this:
Files:
FILE1=c:\upload\File1.xls (108544 bytes)
FILE2=c:\upload\File2.zip (211687 bytes)
Other items:
DESCR1=bla bla
DESCR2=test test
IMPORTANT: The Upload.Files and Upload.Form
collections are populated by the Upload.Save method. Therefore,
it is incorrect to reference either collection before the Save method
is called:
' Incorrect!
Upload.Save( Upload.Form("Path") )