[EdLUG] Help 4

Andrew Ramage andrew.ramage.1963 at gmail.com
Wed May 6 09:53:46 UTC 2020


I tried working on the second half of my website (downloading) and the 
uploading part stopped working.  Can anyone see any reason for this ?  I 
added the echo statements to the file, but none display anything.

_HTML file_

<form action="upload.php" method="post" enctype="multipart/form-data">
     <input type="file" name="fileToUpload" id="fileToUpload">
     <input type="submit" value="Upload music file" name="submit">
</form>

_upload.php_

<html>
<body>


<?php
$target_dir = "Music/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$audioFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

// Check if file already exists
echo First if;
if (file_exists($target_file)) {
     echo "Sorry, file already exists.";
     $uploadOk = 0;
}
echo Second if;
// Allow certain file formats
if($audioFileType != "mp3" && $audioFileType != "ogg"  {
     echo $audioFileType . <br> . "Sorry, only MP3 and OGG files are 
allowed.");
     $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
echo Third if;
     echo"Sorry, your file was not uploaded."; )
// if everything is ok, try to upload file
  else {
     Fourth if;
     if (move_uploaded_file($_FILES ["fileToUpload"]["tmp_name"], 
$target_file)) {
         echo "The file ". basename( 
$_FILES["filndow.alerteToUpload"]["name"]). " has been uploaded."; }
     else {
         echo "Sorry, there was an error uploading your file." }
}
?>

</body>
</html>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.edlug.org.uk/pipermail/edlug/attachments/20200506/bfdaca5f/attachment.html>


More information about the EdLUG mailing list