w3Upload Examples

Examples

Simple Example


First of all we need a form with the file element. Also, it is very important that the form is set to enctype="multipart/form-data".

   Upload.asp

<html>
<head>
    <title> w3 Upload </title>
</head>
<body>
 Uploading files with w3 Upload
 <form action="FormProcess.asp" method="post" enctype="multipart/form-data">
     <input type="file" name="thefile"><br>
     Choose a name: <input type="text" name="name"><br>
     <input type="submit" value="Transmit">
 </form>
</body>
</html>

The following page will receive the form posting and save the uploaded file to our server.

Notice how we use the upload object instead of the Request object. It is important that you do NOT use the Request object, as doing that effectively destroys the file upload stream and you get an ugly error.

This example uses the server variable APPL_PHYSICAL_PATH to save the uploaded file to the same directory as the uploadProcess.asp file resides in. You can save the file to any directory you wish, just make sure the permissions are set correctly (Read more about permissions and uploading in the Q&A section).

   FormProcess.asp

<% @ LANGUAGE="VBSCRIPT" %>
<%
Set upload   = Server.CreateObject( "w3.upload" )

actualName   = upload.Form( "name" )
Set fileName  = upload.Form( "thefile" )
if fileName.IsFile then
     fileName.SaveToFile( Request.ServerVariables( "APPL_PHYSICAL_PATH" ) & "\\" & actualName )
end if
 %>
<html>
<head>
   <title> w3 Upload </title>
</head>
<body>
 <br>
 <br>
 <center>
 Finished!
 </center>
 <br>
 <br>
 <br>
</body>
</html>