[EdLUG] Help 3

Andrew Ramage andrew.ramage.1963 at gmail.com
Fri May 1 14:19:24 UTC 2020


When this is run. $audiofile is null.  Could someone explain  why ?  I 
copied an example from W3scools fpr graphics and changed variable name 
and file types.

<?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
if (file_exists($target_file)) {
     echo "Sorry, file already exists.";
     $uploadOk = 0;
}

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

</body>
</html>




More information about the EdLUG mailing list