The easiest solution is to allow the user to select what ever file he
wants, but before you actually submit to the server, verify that he has
selected the correct file type. Here is a simple html page that only
allows uploads of certain file types.
<HTML>
<HEAD>
<TITLE>My Upload Page</TITLE></HEAD>
<BODY>
<script language="JavaScript">
function verifyFile()
{
if(document.fileUpForm.uploadedFile.value == "") {
alert("Must choose a file first!");
return false;
}
if(document.fileUpForm.uploadedFile.value.length < 5) {
alert("Invalid filename. Must contain proper extension.");
return false;
}
if(document.fileUpForm.uploadedFile.value.search(
/\.(doc|gif|jpg|jpeg|pdf|txt|xls)$/
) == -1) {
alert("Invalid filename extension.");
return false;
}
return true;
}
</script>
<H2>Upload File</H2>
<form name="fileUpForm" method="POST" enctype="multipart/form-data"
action="
http://www.mycomp.com/upload/UploadHandler.aspx"
ID="Form1">
File to upload: <input name="uploadedFile" type="file" size="40"
ID="File1" /><p>
<input type="button" name="submitbutton" value="Submit"
onClick="if(verifyFile()){document.fileUpForm.submit();}"
ID="Button1" />
</form>
</BODY>
</HTML>
The page only allows uploads of files with the following extension:
doc, gif, jpg, jpeg, pdf, txt, and xls. You can modify the list to
allow your file types.
sayed