[EdLUG] Help 4

Tai Kedzierski dch.tai at gmail.com
Wed May 6 11:37:19 UTC 2020


Basically, a lot of syntax errors. It seems your PHP errors are not being
reported to you in the browser, which you certainly want when debugging.
Locate your php.ini file and amend as appropriate

https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display#21429652

>From just reading the code you posted, I noticed the following problems,
there may be more, not actually tested.

+++

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; // <-------------------- quotes around string to be
echoed
    if (file_exists($target_file)) {
        echo "Sorry, file already exists.";
        $uploadOk = 0;
    }
    echo Second if; // <-------------------- quotes
    // Allow certain file formats
    if($audioFileType != "mp3" && $audioFileType != "ogg"  { //
<--------------------did not close condition with ')'  ...
        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; // <-------------------- quotes
        echo"Sorry, your file was not uploaded."; ) //
<-------------------- ...rogue ')' from previous 'if' condition?
    // if everything is ok, try to upload file
     else {
        Fourth if; // <-------------------- forgot "echo" keyword, quotes
        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>


===
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 Wed, 6 May 2020 at 10:53, Andrew Ramage <andrew.ramage.1963 at gmail.com>
wrote:

> 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>
>
> --
> 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/20200506/d86c4be4/attachment-0001.html>


More information about the EdLUG mailing list