title: Sorry, only JPG, JPEG, PNG & GIF files are allowed
body: <p>I am trying to create a script that allows a user to provide us with information and upload 3 images to the database in order to show evidence of the issue they are facing.</p>
  
  <p>I have used a script I found online and have modified it to work with my form. The images are not being uploaded as I get the error 'Sorry, only JPG, JPEG, PNG &amp; GIF files are allowed.' which is shown in the code below. The images I am uploading are definitely .jpg so I cannot understand why this is happening?</p>
  
  <pre><code>&lt;?php
      if(isset($_POST['submitForm'])) {
          $firstname = $_POST['firstname'];
          $lastname = $_POST['lastname'];
          $email = $_POST['email'];
          $organisation = $_POST['organisation'];
          $question_1 = $_POST['question1'];
          $question_2 = $_POST['question2'];
          $question_3 = $_POST['question3'];
          $question_4 = $_POST['question4'];
          $question_5 = $_POST['question5'];
          $image_1 = $_POST['fileToUpload1'];
          $image_2 = $_POST['fileToUpload2'];
          $image_3 = $_POST['fileToUpload3'];
          $message = $_POST['message'];
  
          $target_dir = "/var/www/vhosts/system/removed.co.uk/etc/contact-facility/uploads/";
          $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
          $uploadOk = 1;
          $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
          $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  
          if($check !== false) {
              $uploadOk = 1;
          }
  
          else {
              $uploadOk = 0;
          }
  
          if (file_exists($target_file)) {
              $uploadOk = 0;
          }
  
          if ($_FILES["fileToUpload"]["size"] &gt; 500000) {
              echo "Sorry, your file is too large.";
              $uploadOk = 0;
          }
  
          if($imageFileType != "jpg" &amp;&amp; $imageFileType != "png" &amp;&amp; $imageFileType != "jpeg" &amp;&amp; $imageFileType != "gif" ) {
              echo "Sorry, only JPG, JPEG, PNG &amp;amp; GIF files are allowed.";
              $uploadOk = 0;
          }
  
          $servername = "localhost";
          $username = "removed";
          $password = "removed";
          $dbname = "removed";
  
          try {
              $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
              $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
              $sql = "INSERT INTO contact_facility (first_name, last_name, email_address, hospital_trust, question_1, question_2, question_3, question_4, question_5, image_1, image_2, image_3, message) VALUES ('$firstname', '$lastname', '$email', '$organisation', '$question_1', '$question_2', '$question_3', '$question_4', '$question_5', '$image_1', '$image_2', '$image_3', '$message')";
              $conn-&gt;exec($sql);
  
              $success = "&lt;p style='color: green;'&gt;Thank you for contacting REMOVED.&lt;br /&gt;&lt;br /&gt;We have received your Contact Enquiry and will contact you within 24-48 hours with information regarding your request.&lt;/p&gt;";
          }
  
          catch(PDOException $e) {
              echo $sql . "&lt;br /&gt;" . $e-&gt;getMessage();
          }
  
          $conn = null;
      }
  ?&gt;
  </code></pre>
  
  <p>I don't understand why the images are A: not uploading and B: showing an error on file extension when clearly the image I am uploading is a .jpg.</p>
  
  <p>Where am I going wrong and how would you address this issue?</p>