Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering only PDF file can upload. 1

Status
Not open for further replies.

bataraguru

Programmer
Jun 4, 2002
37
0
0
MY
Hi,
I have setup a file upload form.
The problem is i dont know how to allow only .pdf only to upload.
Please help, its urgent.

Thanks a million...
-- bataraguru --
 
when you're validating your form prior to submit, get the [tt].value[/tt] attribute of the file upload control and check that the last four characters are ".pdf".

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]
 
Do you have the working code of that particular filter.
I dont have any basics in javascripts.

Sorry...
 
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Extension Check Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
var formOK = false;

function validatePDF(objFileControl){
 var file = objFileControl.value;
 var len = file.length;
 var ext = file.slice(len - 4, len);
 if(ext.toUpperCase() == ".PDF"){
   formOK = true;
 }
 else{
   formOK = false;
   alert("Only PDF files allowed.");
 }
}
</script>
</head>

<body>
<form name="MyForm" onsubmit="return formOK;">
Select a PDF file:
<input type="file" name="MyFile" onchange="validatePDF(this)"/>
<input type="submit" value="Submit" />
</form>
</body>
</html>

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]
 
thanks, your code solve my problem.
thanks dwarfthrower.

-- bataraguru -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top