two things one watch out for using quotes for example you have started the echo with a single quote i would use double then change all inside to single quotes.
your problem is with ...
onclick="TestFileType(this.form.uploadfile.value, ['pdf'])"
this should be ....
onclick="TestFileType(this.form.uploadfile.value, ['.pdf'])"
i got the final code to be...
<?
echo "
<html>
<head>
<title>test page</title>
<script language=\"javascript\">
function TestFileType( fileName, fileTypes ) {
if (!fileName) return;
dots = fileName.split(\".\")
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=\"file\" name=\"uploadfile\">
<input type=\"hidden\" name=\"filename\" value=\"{$name}\">
<input type=\"button\" name=\"submit\" value=\"Upload\" onClick=\"TestFileType(this.form.uploadfile.value, ['.pdf'])\">
</form>
<br>
</body>
</html>";
?>
but i would not use php at all to do this i would just use.
<html>
<head>
<title>test page</title>
<script language="javascript">
function TestFileType( fileName, fileTypes ) {
if (!fileName) return;
dots = fileName.split(".")
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="<?php echo $name ?>">
<input type="file" name="uploadfile">
<input type="button" name="submit" value="Upload" onClick="TestFileType(this.form.uploadfile.value, ['.pdf'])">
</form>
<br>
</body>
</html>
there is no point in putting all that in an echo.
hope that helps.