Posted by Gregg Healy on 01/17/05 18:48
I am trying to get the form below to make sure the file type for the upload
is a pdf file. The code below checks, but doesn¹t allow even a pdf file to
upload. Can anybody shed some light on this for me? Is there an easier way
to do this using JS?
<?php
echo '<html>
<head>
<title>test page</title>
<script type="text/JavaScript">
<!-- Begin
function TestFileType( fileName, fileTypes ) {
if (!fileName) return;
dots = fileName.split(".")
//get the part AFTER the LAST period.
fileType = "." + dots[dots.length-1];
return (fileTypes.join(".").indexOf(fileType) != -1) ?
alert(\'That file is OK!\') :
alert("Please only upload PDF format files with the correct .pdf extension.
Please select a new file and try again.");
}
// -->
</script>
</head>
<body>
<form method="post" action="upload.php" enctype="multipart/form-data">
<input type="hidden" name="filename" value="'.$name.'">
<input type="file" name="uploadfile">
<input type="button" name="Submit" value="Upload"
onclick="TestFileType(this.form.uploadfile.value, [\'pdf\'])"><br>
</body>
</html>
';
?>
--
Gregg Healy
Service Specials Direct
800 230-8268
[Back to original message]
|