Next you see is the <input> tag having a type value as "FILE" so when you put this is a regular HTML page the browser understands that a file has to be uploaded and hence you see a button for "Browse..."
<input TYPE="FILE" NAME="fileUpload">
The submit code (below) on the other hand as below POST's the data to the server side and the file is uploaded to the directory specified.
<input type="submit" name="submiter" value="Submit">
Please make sure you have PWS/IIS running on your machine which supports server side code like ASP in this case.
Make sure you put all the files in the same virtual directory!
Recommended Spec
Windows 2000 (Win98 with PWS is also fine)
RAM: 128MB
IIS 4.0 and up (IIS 5.0 recommended)
The working code
<html>
<%
if Request.QueryString("uploader") = "true" then
Set upl = Server.CreateObject("SoftArtisans.FileUp") ' Creating upl object!
basePath = Server.MapPath(".") ' mapping the default path where files will be stored on the hard disk!
upl.Path = basePath & "\uploads"
if not upl.IsEmpty Then 'we check if the object is empty or has a null value!
'on error resume next
upl.Save 'Saving the uploaded file
strFile = upl.UserFilename 'Storing name of the file in a temporary variable!
strFileTemp = strFile
aryFileName = Split(strFile,"\")
lastVal = UBound(aryFileName) 'Checking the Ubound after spliting the file name!
strFile = aryFileName(lastVal)
strFileTemp = strFile 'actual file name with its type stored in a variable!
end If
end if
%>
<head>
<link rel="stylesheet" href="styler.css">
<script>
//This function checks to see if the user has selected some file using browse option
//If there is no proper path then it alerts user to please select a file.
function checkForm()
{
if (document.form1.fileUpload.value.length>2)
{
return (true);
}
else
{
alert("Please select an image file to upload.");
return (false);
}
}
</script>
<title>Image Upload</title>
</head>
<body bgcolor="#edf3f8">
<form ENCTYPE="MULTIPART/FORM-DATA" ACTION="index.asp?uploader=true" METHOD="POST" id="form1" name="form1" onsubmit="javascript:return checkForm();">
<table width="100%">
<tr>
<td class="contentBold" height="20">
Uploading files using SAFileup utility!<br>
</td>
</tr>
<tr>
<td class="content" height="20"></td>
</tr>
</table>
<%if Request.QueryString("uploader") = "true" then%>
<table width="100%">
<tr>
<td class="content2" height="20">
Your file <b><%=strFileTemp%></b> was successfully uploaded!<br><br>
<a class="upload" href=#" onclick="history.back(-1);">Click to upload more files.<a>
</td>
</tr>
</table>
<%else%>
<table width="100%">
<tr>
<td class="contentBold" height="20">
Select an image file you would like to upload.<br>
<input TYPE="FILE" NAME="fileUpload">
</td>
</tr>
<tr>
<td class="content"><img src="pixel.gif" height="10" width="1"></td>
</tr>
</table>
<div align="left"><input type="submit" name="submiter" value="Submit"></div>
<%end if%>
</form>
</body>
</html>
Comments