Adding a Second File

You've now seen how to upload a file and capture additional form elements. What if you wanted to transmit multiple files with a single form submit?

To add an additional file, just add another <INPUT TYPE="FILE"> tag to your form.

Even though the Internet Standard specification for HTTP Upload (RFC 1867) permits filenames with wildcards("*.doc"), neither Netscape Navigator nor Microsoft Internet Explorer support names with wildcards at this time. When they do, the current version of SA-FileUp will be able to process filenames with wildcards. If you want to use wildcards today, you may want to look into one of our client-side products such as SA-JFile or SA-XFile. The tutorial exercises for Client-Side Solutions demonstrate using these products.

Without using a complementary client-side tool, 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>

Formresp2.asp contains the following code:

	<%@ 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.FormEx("f1").SaveAs "C:\temp\upload1.out" %><BR>
	Total Bytes Written for File 1: <%=upl.FormEx("f1").TotalBytes%>
	<% upl.FormEx("f2").SaveAs "C:\temp\upload2.out" %><BR>
	Total Bytes Written for File 2: <%=upl.FormEx("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.FormEx("f1").SaveAs "C:\temp\upload1.out" %><BR>
	<% upl.FormEx("f2").SaveAs "C:\temp\upload2.out" %><BR>

Like the upl.FormEx syntax, we use upl.FormEx("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 .FormEx("file-element-name") syntax.

All of the methods and properties (such as TotalBytes) are available when using this syntax. For example, to list the total number of bytes for File 1, you could use the following line of code:

	Total Bytes Written for File 1: <%=upl.FormEx("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?

 

 

Previous Page Next Page