2012-06-19 4 views
0

이것이 작동하지 않는 이유를 모르겠습니다. 그것은 아주 쉬워야합니다.PHP - 파일 업로드 실패

upload.php로 :

$uploaddir = '/usr/share/nginx/www/pitfax/upload/'; 
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']); 

echo "<p>"; 

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { 
    echo "File is valid, and was successfully uploaded.\n"; 
} 
else { 
    echo "Upload failed"; 
} 

echo "</p>"; 
echo '<pre>'; 
echo 'Here is some more debugging info:'; 
print_r($_FILES); print "</pre>"; 

폼 페이지 :

<form enctype="multipart/form-data" action="upload.php" method="POST"> 
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000" /> 
    Send this file: <input name="userfile" type="file" /> 
    <input type="submit" value="Send File" /> 
</form> 

오류 출력된다 :

Upload failed 

Here is some more debugging info:Array (
    [userfile] => Array 
     (
      [name] => test.pdf 
      [type] => application/pdf 
      [tmp_name] => /tmp/phptM0p4w 
      [error] => 0 
      [size] => 1287464 
     ) 

) 
  • 웹 서버 :,745,151 Nginx에
  • upload.php에 대한
  • 권한 : upload 디렉토리 (644)
  • 권한 : 755
  • 을 루트 사용자와 SSH에서 작업.
  • 편집 :이 upload_max_filesize = 2M
  • 편집 : post_max_size을 = 8M

또 한가지! 업로드가 완료되면 업로드 된 파일의 절대 경로를 가져오고 싶습니다. (예 : /usr/share/nginx/www/pitfax/upload/test.pdf)

+3

오류 로그에는 무엇이 있습니까? – zerkms

+1

업로드 디렉토리를 777로 설정해 보셨습니까? –

+0

@LukePittman 예, 작동하지 않았습니다. – xperator

답변

1

$을 UploadFile의 값은 업로드 /있는 test.pdf하지만 당신은 내가보다가 /usr/share/nginx/www/pitfax/upload/test.pdf 싶은 경우 문제가 될 것이라고 의심하십시오.

$uploadfile = '/usr/share/nginx/www/pitfax/upload/' . $_FILES['userfile']['name']; 

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { 
    echo "File is valid, and was successfully uploaded.\n"; 
} else { 
    print_r ($_FILES); 
} 

편집 : 코드 서식

이 코드를 사용해보십시오.

+0

Ok'echo $ uploadfile;'의 출력은 꼭 그래야합니다. 그러나 업로드는 여전히 실패합니다./tmp/phpbGRbCg [오류] => 0 [크기] => 1287464) 출력은'Array ([userfile] => Array ([name] => test.pdf [type] => 응용 프로그램/pdf [tmp_name])' – xperator

+0

다른 사람이 문제를 해결하려고 할 때 디버깅 서비스가 아니라고 들었습니다. 그래서 나는이 시점에서 내가 할 수있는 일이 많지 않다는 것을 두려워합니다. 힌트를 위해 로그 파일 (아파치 오류 로그)을 확인하고, 모든 변수를 에코하고, 고정 된 파일 이름으로 시도해보십시오. –

+0

다시 777로 업로드 디렉토리의 권한을 변경하고 갑자기 업로드가 작동했습니다! 감사! – xperator