title: move_uploaded_file not writing to server, nor returning anything
body: <p>I am trying to store a file, along with a few text fields, from an HTML form to my web server. The text is being written absolutely fine, however nothing is happening with the image. I have checked for errors, and none are showing up. The image is also being received in the email.
  I believe the permissions are fine too - they are exactly the same on <code>/img/gallery/</code> and <code>/img/gallery/data/</code>.</p>
  
  <p>Here is my PHP for the form:</p>
  
  <pre><code>&lt;?php
  include 'loadImages.php';
  require_once('class.phpmailer.php');
  
  $name = $_POST['name'];
  $email = $_POST['email'];
  $location = $_POST['location'];
  $desc = $_POST['desc'];
  
  /**
   * PHPMailer simple file upload and send example
   */
  $msg = '';
  if (array_key_exists('userfile', $_FILES)) {
      // First handle the upload
      // Don't trust provided filename - same goes for MIME types
      // See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
      $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
      if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
          // Upload handled successfully
          // Now create a message
          // This should be somewhere in your include_path
          require 'PHPMailerAutoload.php';
          $mail = new PHPMailer;
          $mail-&gt;setFrom('gallery@####.co.uk', 'Website');
          $mail-&gt;addAddress('gallery@####.co.uk');
          $mail-&gt;Subject = 'Image Submission Recieved';
          $mail-&gt;msgHTML("&lt;b&gt;Name&lt;/b&gt;: $name&lt;br&gt;&lt;b&gt;Email&lt;/b&gt;: $email&lt;br&gt;&lt;b&gt;Location&lt;/b&gt;: $location&lt;br&gt;&lt;b&gt;Description&lt;/b&gt;: $desc");
          // Attach the uploaded file
          $mail-&gt;addAttachment($uploadfile, 'Image');
          if (!$mail-&gt;send()) {
              $msg = "Mailer Error: " . $mail-&gt;ErrorInfo;
          } else {
              $msg = "Your message has been sent.";
          }
      } else {
          $msg = 'Failed to move file to ' . $uploadfile;
      }
  
      $date = date('Y-m-d_H-i-s');
  
      $path = $_SERVER['DOCUMENT_ROOT'].'/img/gallery/data/';
      $filename = $date.".txt";
  
      $file = fopen($path.$filename, "w") or die("Something went wrong storing your photo information");
        fwrite($file, $name . "\n");
        fwrite($file, $location . "\n");
        fwrite($file, $desc . "\n");
        fwrite($file, $email . "\n");
        fwrite($file, "Valid: False");
      fclose($file);
  
      $name = $_FILES['userfile']['name'];
      $path = $_SERVER['DOCUMENT_ROOT'].'/img/gallery/';
      $filename = $date . "." . pathinfo($name, PATHINFO_EXTENSION);
  
      $target = $path . $filename;
      echo $target;
  
      echo move_uploaded_file( $_FILES['userfile']['tmp_name'], $target);
  }
  
  $images = loadImages();
  $imageData = LoadImageData();
  ?&gt;
  </code></pre>
  
  <p>$_FILES:</p>
  
  <pre><code>1Array ( [userfile] =&gt; Array ( [name] =&gt; hairy sun.jpg [type] =&gt; image/jpeg [tmp_name] =&gt; /tmp/phpWweCkX [error] =&gt; 0 [size] =&gt; 49526 ) )
  </code></pre>
  
  <p>If you need to see anything else, I will upload it.</p>