2012-09-08 2 views
2

그래서 move_uploaded_file() 문제에 대해 this question을 읽었습니다. 그러나, 내 아파치 전원 localhost 램프 스택에, 잘 작동합니다. 그래서 나는 그것이 파일 시스템/경로일지도 모르고 코드 일 수도 없다고 생각한다.nginx에서 파일 업로드/이동 temp가 작동하지 않습니다.

로컬로 사이트에 파일을 업로드 할 때 작동합니다. 나는 (nginx를 전원) 품질 보증 서버에있을 때

하지만, 난이 오류를 얻을 :

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" 

를이 내가 파일 업로드 처리하기 위해 쓴 코드입니다

public function fileUploadToProject($project_id) { 
    if ($_FILES["upload-file"]["error"] > 0) { 
     echo "Error: " . $_FILES["file"]["error"] . "<br />"; 
    } 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->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; 
     } 

    } 
} 

그래서, 임시 파일을 nginx에서 파일 시스템으로 옮기는 것에 대해 알아야 할 것이 있습니까? 아니면 단순히 경로 문제라고 생각합니까? 코드 문제?

또한

, 그 라인 (516)이있다 참고 : $uploaded = move_uploaded_file($tmp_name, $destination);

답변

5

폴더에 권한 문제가 있습니다.

해당 경로에있는 /files 디렉토리가 실제로 존재하지 않습니다. 나는 어떻게 든 폴더가 단순히 거기에 없었다는 것을 결코 깨닫지 못했습니다. 오케이.

chown -R root:userFromStep1 files 

그때 내가 chmod 디렉토리로했다 :

ps aux | grep "nginx" 

그때 내가 chownfiles 디렉토리를 가지고 :

다음, 내가 PHP를 실행 Nginx에 의해 사용 된 어떤 사용자를 결정했다 :

chmod g+w files 

매력이야.

0

정확한 경로를 제공하는 대신 __FILES__을 사용하여보십시오 수 있습니다. 때문에 nginx 문제가되지 않습니다.

관련 문제