Adding a Second File

The previous example showed how to upload a file and capture addition form elements. What if you wanted to transmit multiple files with a single form submit?

To add a second (or other file), just add another <INPUT TYPE="FILE"> tag to your form.

Even though the Internet Standard specification for HTTP Upload (RFC 1867) permits wildcarded filenames ("*.doc"), neither Netscape Navigator or Microsoft Internet Explorer support wildcarded names at this time. When they do, the current version of SA-FileUp will be able to process wildcarded filenames. For now, it is necessary to have an additional input tag for every file you want to upload.

Here is an example:

	<HTML>	<HEAD>
	<TITLE>Please Upload Two Files</TITLE>
	</HEAD>
	<BODY>
	<form enctype="multipart/form-data" method="post" action="formresp2.asp">
	Enter first filename:  <input type="file" name="f1"><br>
	Enter second filename: <input type="file" name="f2"><br>
	<input type="submit">
	</form>
	</BODY>
	</HTML>

Here would be the file 'formresp2.asp':

	<%@ LANGUAGE="VBSCRIPT" %>
	<HTML><HEAD>
	<TITLE>Multiple File Upload Results</TITLE>
	</HEAD>
	<BODY>
	Thank you for uploading your files.<br>
	<% Set upl = Server.CreateObject("SoftArtisans.FileUp") %>
	<% upl.Form("f1").SaveAs "C:\temp\upload1.out" %><BR>
	Total Bytes Written for file 1: <%=upl.Form("f1").TotalBytes%>
	<% upl.Form("f2").SaveAs "C:\temp\upload2.out" %><BR>
	Total Bytes Written for file 2: <%=upl.Form("f2").TotalBytes%>
	</BODY>
	</HTML>

Let's look at the form's processing (formresp2.asp).

In this case we are referring to the file elements explicitly by name.

	<% upl.Form("f1").SaveAs "C:\temp\upload1.out" %><BR>
	<% upl.Form("f2").SaveAs "C:\temp\upload2.out" %><BR>

Like the upl.Form syntax, we use upl.Form("name-of-the-form-element") to refer to the value of the file.

The older method, upl.SaveAs, would still work, but would refer to the first file element that was found. This is ambiguous. So, when uploading multiple files, be explicit and use the .Form("file-element-name") syntax.

All of the methods and properties, such as the TotalBytes are available when using this syntax. For example,

	Total Bytes Written for file 1: <%=upl.Form("f1").TotalBytes%>

Internally, SA-FileUp has created an instance of another object to represent the uploaded file. This object is called the SAFile object. The SAFile object has properties and methods as well. See the Reference Section for details.


What did we learn?

Great - you've got lots of uploads working. What if you wanted to Limit the Size of the Upload?