Your First Upload

 

Uploading Files is easy using SA-FileUp.

Here is a simple HTML form that will upload a file:

	<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" name="f1"><br>
	<input type="submit">
	</form>
	</BODY>
	</HTML>

Here would be the file 'formresp.asp'

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

 

And that's it!

Let's walk through the sample and see what is going on.

Look at the definition of the form. When using a form to upload files, the following items must be set:

  1. The FORM must have a tag of ENCTYPE="multipart/form-data".
  2. The <INPUT TYPE="FILE"> must have a tag of NAME= .

This tells the browser to transmit the contents of the file when posting the form.

Let's look at the form's processing (formresp.asp). The following line creates an instance of the SA-FileUp object:

	<% Set upl = Server.CreateObject("SoftArtisans.FileUp") %>

The following line invokes the .SaveAs method and passes the name of the web server's destination file as a parameter.

	<% upl.SaveAs "C:\temp\upload.out" %><BR>

In two lines you've uploaded a file!

For bonus points, the following line retrieves the TotalBytes property and displays it to the user.

	Total Bytes Written: <%=upl.TotalBytes%>


What did we learn?

Simple, right? Now, let's add Multiple Form Elements