0

PDF file uploader is spitting out an error, could anyone help?

Parse error: syntax error, unexpected T_VARIABLE in /home/stylecraft/domains/stylecraft-yarns.co.uk/public_html/dev/_cms/upload_pdf2.php on line 37

<?php
$allowedExts = array("jpg", "jpeg", "gif", "png", "pdf");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ($_FILES['file']['error'] !== UPLOAD_ERR_OK) {
    die("Upload failed with error " . $_FILES['file']['error']);
}
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES['file']['tmp_name']);
$ok = false;
switch ($mime) {
   case 'image/jpeg':
   case 'application/pdf'
        $ok = true;
   default:
       die("Unknown/not permitted file type");
}
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

    if (file_exists("../pdf/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists: ";
      echo "<p>Image URL: <strong>" . $preferences->PREF_SHOPURL . "/pdf/" . $_FILES["file"]["name"] . "</strong></p>";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "../pdf/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "pdf/" . $_FILES["file"]["name"];
      echo "<p>&nbsp;</p>";
      echo "<p>PDF URL: <strong>" . $preferences->PREF_SHOPURL . "/pdf/" . $_FILES["file"]["name"] . "</strong></p>";
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?> 
2
Contributors
2
Replies
12
Views
2 Years
Discussion Span
Last Post by jonlloydd
0

the error is at 'else' on line 17.
there is no 'if' to 'else'. You should break after your switch cases as well(ok = true; break;). may not cause issues right now but you should always end the excecution when the conditions have been met.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.