This example shows how to upload a form containing a mix of standard form and file input fields.



Our multipart HTML form contains one file field and an assortment of other fields. It asks the visitor to upload their favorite picture, type in the name of their favorite color and click a number of checkboxes to choose what kinds of ice cream they like. This page then submits data to mixedupload.asp.

<form method="post" action="mixedupload.asp" enctype="multipart/form-data">
What is your favorite picture?<br>
<input type="file" name="file"><br>
What is your favorite color?<br>
<input type="text" name="color" value="purple"><br>
What types of ice cream do you like?<br>
<input type="checkbox" name="flavor" value="chocolate">Chocolate<br>
<input type="checkbox" name="flavor" value="butterscotch">Butterscotch<br>
<input type="checkbox" name="flavor" value="vanilla">Vanilla<br>
<input type="submit" name="submit" value="submit">


We create an XForm object. To start with we want to report the color that our visitor chose. We simply reference our XForm object, passing in the name of the field we want.

Next we want to write out the flavors chosen. Because all the checkboxes have the same name we have to loop through all the fields named "flavor" getting the value of each and writing it out.

Finally we deal with the file upload. If a file was uploaded we save it into a directory called "images" (the virtual path is relative to the location of the current page). We use the FileName property to give it a URL safe name, identical or similar to the original name of the file.

<% @Language="VBScript" %>
Set theForm = Server.CreateObject("ABCUpload4.XForm")

Response.Write "Your favorite color is "
Response.Write theForm("color") & "<br>"

Response.Write "You like these types of ice cream<br>"
For i = 1 to theForm("flavor").Count
  Response.Write theForm("flavor")(i) & "<br>"

Set theField = theForm.Files("file")
If theField.FileExists Then
  theField.Save "images/" & theField.FileName
  Response.Write "File " & theField.FileName & " uploaded"
  Response.Write "No file uploaded"
End If