[EdLUG] Help 7

Tai Kedzierski dch.tai at gmail.com
Tue May 12 13:53:17 UTC 2020


There are a couple errors I can see here right off the bat.

The most important one though, would be that you don't seem to have turned
on debugging messages for being sent to the browser, because they are clear
syntax errors, and would have appeared to you ...! ;-)

Include this at the top of the PHP file:

<?php
error_reporting(E_ALL);
?>


Then run your code again. The error reporting should display and make
debugging easier. :-)

===
Tai Kedzierski
Linux Operations and Deployments Engineer


I use LibreOffice <https://www.libreoffice.org/> , a free,
Freedom-respecting replacement for MS Office

*Open Source Free Software is a matter of liberty, not price.*
https://www.fsf.org/about/what-is-free-software



On Tue, 12 May 2020 at 14:49, Andrew Ramage <a.ramage at blueyonder.co.uk>
wrote:

> I cannot understand why my site uploads a file then stops working.  Is
> something wrong with the HTML ?
>
> *HTML*
>
>
> <form action="upload.php" method="post" enctype="multipart/form-data">
>     <input type="file" name="fileToUpload" id="fileToUpload" multiple>
>     <input type="submit" value="Upload music file" name="submit">
> </form>
>
> *upload.php*
>
> <!doctype html>
>
> <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";
> if ($uploadOk == 0) {
>     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>
>
> --
> EdLUG mailing list
> EdLUG at lists.edlug.org.uk
> https://lists.edlug.org.uk/mailman/listinfo/edlug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.edlug.org.uk/pipermail/edlug/attachments/20200512/7c673597/attachment.html>


More information about the EdLUG mailing list