title: File upload / move temp not working on nginx
body: <p>So, i've read <a href="https://stackoverflow.com/questions/9952329/php-file-upload-move-uploaded-file-not-working">this question</a> about move_uploaded_file() problems. However, on my apache-powered localhost lamp stack, its working just fine. So i think it may be a filesystem / path thing, and not a code thing.</p>
  
  <p>when uploading files to my site locally, it works.</p>
  
  <p>but when I'm on the QA server (which is nginx powered), i get this error:</p>
  
  <pre><code>2012/09/08 15:34:21 [error] 11794#0: *5187 FastCGI sent in stderr: "files not empty
  PHP Warning:  move_uploaded_file(/var/www/qa.mysite.com/mysite/app/files/maps-aprilfools.tiff): failed to open stream: No such file or directory in /var/www/qa.mysite.com/mysite/app/models/files.php on line 516
  PHP Warning:  move_uploaded_file(): Unable to move '/tmp/phpvdtznP' to '/var/www/qa.mysite.com/mysite/app/files/maps-aprilfools.tiff' in /var/www/qa.mysite.com/mysite/app/models/files.php on line 516" while reading response header from upstream, client: 72.xxx.xxx.xxx, server: qa.mysite.com, request: "POST /projects/3/files HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "qa.mysite.com", referrer: "http://qa.mysite.com/projects/3/files"
  </code></pre>
  
  <p>and this is the code that I wrote to handle uploading a file:</p>
  
  <pre><code>public function fileUploadToProject( $project_id ) {
      if ($_FILES["upload-file"]["error"] &gt; 0) {
          echo "Error: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
      } else {
  
          $dbSuccess      = false;
  
          $tmp_name       = $_FILES["upload-file"]["tmp_name"];
          $name           = $_FILES["upload-file"]["name"]; // someFile.ext
          $size           = $_FILES['upload-file']['size']; //size in bytes
          $mime           = $_FILES['upload-file']['type']; //size in bytes
  
          $destination    = __FILES__.'/'.$name;
          $uploaded       = move_uploaded_file( $tmp_name, $destination );
  
          // add entry to database.
  
          /*
           * null because there is no container yet.
           * We're only uploading to local
           */
          $user_container_name = null; 
  
          $uploaded_by = LoggedInUser::get_user_id();
  
          /*
           * Set this 1 when we're not dealing with our external fileserver
           */
          $isLocal = 1;
  
          /*
           * Probably shouldn't do this forever for storage size reasons, but for now its useful.
           */
          $localPath = $destination;
  
          $task_id = null;
  
          if( $uploaded ) {
          $dbSuccess = $this-&gt;insertFileRefService( $task_id, 
                                                    $project_id,
                                                    $user_container_name, 
                                                    $name,
                                                    $mime, 
                                                    $size,
                                                    $uploaded_by,
                                                    $isLocal,
                                                    $localPath
                  );
              if($dbSuccess) {
                  return true;
              } else {
                  // should I rollback / delete that file?
                  return false;
              }
          } else {
              return false;
          }
  
      }
  }
  </code></pre>
  
  <p>So, is there anything I should know about moving temp files to my filesystem with on nginx? or do you think it is simply a path problem? code problem?</p>
  
  <p>Also, please note that line 516 is this: <code>$uploaded = move_uploaded_file( $tmp_name, $destination );</code></p>