|
Uploading with SA-FileUp --
Accessing Multiple Form Elements
Form and FormEx
You can usually use ASP's Request.Form object to access
form values. However, when uploading
files, you must change the form's encoding type to
"multipart/form-data". The ASP Request.Form object
does not understand data transmitted using this encoding
type.
SA-FileUp includes two objects that provide the functionality
of the ASP Request.Form object, but can understand the
encoding type that is specific to file uploads. The two
objects are Form and FormEx.
Form is used to access the values of solitary form elements.
FormEx handles collections of form elements (e.g., listboxes,
radio buttons, multiple files, etc.). Using FormEx to
access solitary form elements may produce an error. To prevent errors, use each
object only in its appropriate context. Syntactically,
FormEx may only be used as follows,
- In a "For...Each" statement, i.e., "For each item in upl.FormEx(multipart)"
- With collection index numbers, i.e., "FormEx("name").index"
The Form Definition
To submit information with the upload,
include additional <INPUT> tags. The form defined below contains a text
input for the file description.
filename=/sa/test/multipartform.asp
<html>
<head>
<title>Please Upload Your File</title>
</head>
<body>
<form enctype=multipart/form-data method=post action=multipartformrespond.asp>
<table>
<tr>
<td>Enter file description:</td>
<td><input type=text name=descrip></td>
</tr>
<tr>
<td>Select file:</td>
<td><input type=file name=f1></td>
</tr>
<tr>
<td><input type=submit value="Submit"></td>
<td></td>
</tr>
</table>
</form>
</body>
</html>
The Server-side Processing
To access a form value using SA-FileUp's Form object, refer
to it explicitly by name, as in the following example.
filename=/sa/test/multipartformrespond.asp
<HTML><HEAD>
<TITLE>Multipartformrespond.asp by softwareartisans.com</TITLE>
</HEAD><BODY>
Thank you for uploading your file.<br><br>
<%
Set upl = Server.CreateObject("SoftArtisans.FileUp")
upl.Path = Server.Mappath ("/upload") & "/" & "tests"
upl.Save
strFilename = Mid(upl.UserFilename, InstrRev(upl.UserFilename, "\") + 1)%>
File name: <%=strFilename%><br><br>
File description: <%=upl.form("descrip")%>
</BODY></HTML>
Note: Since the form contains only one <INPUT> of
TYPE="FILE",
you do not have to refer to it by name.
|