[EdLUG] Help 8

Matthew Rankine matthew at mrankine.com
Thu May 14 09:34:07 UTC 2020


I saved this script and visited the page in my browser. PHP reports a
helpful error message:

*Parse error*: syntax error, unexpected '<' in */var/www/sandbox/upload.php* on
line
*24*


After correcting line 24, I visited it again and PHP reported:

*Parse error*: syntax error, unexpected '}', expecting ',' or ';' in
*/var/www/sandbox/upload.php* on line *38*


After correcting line 38, there were no further syntax errors. I haven’t
checked whether the script does what is intended, but the syntax is at
least correct.


If you aren't seeing these PHP error messages, you need to turn them on. It
looks like you're using Apache. Based on a quick Google, you should add the
following into your php.ini file:

error_reporting = E_ALL
display_errors = On
display_startup_errors = On

It looks like there's already a php.ini file in the same directory as your
scripts; add the above directives to it.

Note that I had to save your script as upload.php not upload.html to get it
to run.

It might take a couple of goes to get PHP and Apache sorted such that they
output all errors (including parse errors), but it will be worth it as it
makes debugging much easier than simply eyeballing the code for errors.

Best of luck,
Matthew


On Thu, 14 May 2020 at 09:55, Andrew Ramage <andrew.ramage.1963 at gmail.com>
wrote:

> I still do not see a syntax error in this file:
>
> *upload.html*
>
> <!doctype html>
>
> <html>
>
>
> <?php
>    error_reporting(E_ALL);
>
>
> $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."
>          }
>     }
> ?>
>
> </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/20200514/be1f32d1/attachment.html>


More information about the EdLUG mailing list