I have been working on a script to upload mp3, doc, and pdf files and put them on a folder on my server usin PHP. I have tried writing 3 different scripts all seem to be failing through the if option statements. Can anyone tell me where I am going wrong please ? Code is below :
if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $file=$_FILES['file']['name']; // if it is not empty if ($file) { // get the original name of the file from the clients machine $filename = stripslashes($_FILES['file']['name']);
// get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); // if it is not a known extension, we will suppose it is an error, print an error //message //and will not upload the file, otherwise we continue if (($extension != "doc") && ($extension != "jpg") && ($extension != "pdf")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { // put files in folder
else { echo "<h1>There is a problem</h1>"; } } } } else {
?>
<body>
<form name="newad" method="post" enctype="multipart/form-data" action=""><input type="hidden" name="phpMyAdmin" value="4594f30712f4fabaff6997416810f3f2" /> <table width="300" align="center" id="uploadImg"> <tr> <td colspan="2"><h1>Upload Files</h1></td> </tr> <tr> <td colspan="2"> <p align="center" style="font-size:10px;">You can upload files with the <strong>.MP3, doc and pdf </strong> extension using this form. Please make sure that all your MP3's have been ID3 tags or they will not display in the flash player.</p></td> </tr> <tr> <td>Please choose a file :</td> <td><input name="file" type="file" /></td> </tr> <tr> <td colspan="2"><div align="center"> <input type="submit" value="Upload File" name="Submit" /> </div></td> </tr> <tr> <td colspan="2"><div align="center"><a href="javascript:window.close()" title="Close Window">Close Window</a></div></td> </tr> </table>