|
The Files property contains a collection of all the file upload
fields from the current form. Items within the collection can be
referenced by name or number. Each item is an XField object.
Note that this collection contains all file input fields. If
your client did not select a file to upload, some of these fields
may be empty. You can use the XField.FileExists
property to check whether a file was selected or not.
Saving an uploaded file
Given the following form.
<form method="post" action="myup.asp"
enctype="multipart/form-data">
<input type="file" name="upload"><br>
<input type="submit" name="submit" value="submit">
</form>
You might use the following code to save your uploaded file.
Set theForm = Server.CreateObject("ABCUpload4.XForm")
If theForm.Files("upload").FileExists Then
theForm.Overwrite = True ' overwrite existing files
theForm.AbsolutePath = True ' save using absolute
path
theForm.Files("upload").Save "c:\upload.dat"
End If
Saving all uploaded files
If you are uploading multiple files you might like to save them
using a slightly different method. Given the following form.
<form method="post" action="myup.asp"
enctype="multipart/form-data">
<input type="file" name="upload_1"><br>
<input type="file" name="upload_2"><br>
...
<input type="file" name="upload_N"><br>
<input type="submit" name="submit" value="submit">
</form>
You might use the following code ...
Set theForm = Server.CreateObject("ABCUpload4.XForm")
theForm.Overwrite = True ' overwrite existing files
For Each theFile in theForm.Files
If theFile.FileExists Then
' save in virtual directory
theFile.Save theFile.SafeFileName
End If
Next
Or alternatively ...
Set theForm = Server.CreateObject("ABCUpload4.XForm")
theForm.Overwrite = True ' overwrite existing files
For i = 1 To theForm.Files.Count
Set theFile = theForm.Files(i)
If theFile.FileExists Then
' save in virtual directory
theFile.Save theFile.SafeFileName
End If
Next
|