This example shows how a basic upload works.



To start with you need an HTML form with a file field in it. Note that only multipart forms support file upload - hence enctype="multipart/form-data". If you try to upload a file from a form that isn't multipart encoded you will not receive any data. This page submits data to basicupload.asp.

<form method="post" action="basicupload.asp" enctype="multipart/form-data">
<input type="file" name="filefield"><br>
<input type="submit" name="submit" value="submit">


The Active Server Page simply creates an XForm object and saves the uploaded file out as myupload.dat.

By default the filename is virtual - a URL relative to the current page - so the file will be saved in the same directory as the basicupload pages. You can specify absolute pathnames if you set the XForm AbsolutePathname property to True.

Before we save we set the XForm Overwrite property to True. This ensures that we overwrite any existing file we may have previously uploaded. We also check that the user has selected a file to upload.

<% @Language="VBScript" %>
Set theForm = Server.CreateObject("ABCUpload4.XForm")
theForm.Overwrite = True
If theForm.Files("filefield").FileExists Then
   theForm.Files("filefield").Save "myupload.dat"
End If
File uploaded...