title: PHP Mobile Camera Upload Not Working
body: <p>I have been working on this for a few days now, looking on previous questions/answers on here from other people and I have yet to find an answer. The idea behind this is to allow a mobile camera to upload a photo, compress it, store it and record the name of the file in the database.</p>
  
  <p>If I use this code on my PC, it works, no problem. If I use my phone camera, I get either Page not working - ERROR 500 or the form says it has uploaded and I check, the database has the name, but on the server, 'File Not Found'. I have also tried uploading a saved image from my phone and the same happens.</p>
  
  <p>Below is the PHP Script:</p>
  
  <pre><code>$db = new PDO('mysql:host=host;dbname=db', 'user', 'pass');
  
  function compress($source, $destination, $quality) {
  
      $info = getimagesize($source);
  
      if($info['mime'] == 'image/jpeg') {
          $image = imagecreatefromjpeg($source);
      } else if($info['mime'] == 'image/gif') {
          $image = imagecreatefromgif($source);
      } else if($info['mime'] == 'image/png') {
          $image = imagecreatefrompng($source);
      }
  
      imagejpeg($image, $destination, $quality);
  
      return $destination;
  
  }
  
  if(isset($_POST['submit'])) {
  
      $target = $_SERVER["DOCUMENT_ROOT"].'/images/uploads/'
      $target = $target . basename($_FILES['file']['name']);
  
      $photo_name = ($_FILES['file']['name']);
      $imageFileType = pathinfo($target, PATHINFO_EXTENSION);
      $file = $photo_name;
  
      $query = "INSERT INTO jrtwall_images (imgurl) VALUES ('$file')";
      $result = $db-&gt;query($query);
  
      if($result &amp;&amp; compress($_FILES['file']['tmp_name'], $target, 50)) {
  
          header("Location: /?pid=1&amp;success=1");
          exit();
  
      } else {
  
          header("Location: /?pid=1&amp;error=1");
          exit();
  
      }
  
  }
  </code></pre>
  
  <p>Here is my HTML:</p>
  
  <pre><code>&lt;form action="core/engines/upload-v2.eng.php" method="post" autocomplete="off" enctype="multipart/form-data"&gt;
  
      &lt;input type="file" name="file" /&gt;
      &lt;input type="submit" name="submit" value="Upload &amp;amp; Send" /&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p><code>print_r($_FILES['file']);</code> shows:</p>
  
  <pre><code>Array([name] =&gt; 15316729868972697354228305840469.jpg [type] =&gt; image/jpeg [tmp_name] =&gt; /tmp/phpAvNZZF [error] =&gt; 0 [size] =&gt; 4649129)
  </code></pre>
  
  <p>Any help what-so-ever would be greatly appreciated. I'm running PHP 5.6.</p>
  
  <p><strong>Things I Have Tried:</strong></p>
  
  <ul>
  <li>Enabling Cross Origin</li>
  <li>Increasing both Upload and Post size limits in my php.ini</li>
  <li>Uploading with out the compression function (Works, but I NEED the compression)</li>
  <li>Adding 'capture' and 'image/*' to the input on the form</li>
  <li>Checking <code>$_FILES</code> array for errors, None/Error 0</li>
  <li>Adding $db (connection) to the Compress method</li>
  <li>Tried code on XAMPP and it worked after changing <code>$target</code> to <code>$target = $_SERVER["DOCUMENT_ROOT"].'/images/uploads/';</code> however, the tweak did not work once uploaded to the live server, still get ERROR 500. (Awaiting tech support to send me a copy of the server error log as I can't access it through my FTP or cPanel).</li>
  <li>Tried upgrading to PHP 7, 7.1, 7.2. No luck so reverted back to PHP 5.6.</li>
  </ul>