我不明白爲什麼這不起作用。它應該很容易。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
)
)
- 網絡服務器:NGINX 個
- 權限
upload.php
:644個 - 權限
upload
目錄:755 - 在SSH與根用戶工作。
- 編輯:的upload_max_filesize = 2M
- 編輯:的post_max_size = 8M
另一件事!上傳完成後,我想獲取上傳文件的絕對路徑。 (例如:/usr/share/nginx/www/pitfax/upload/test.pdf
)
什麼是錯誤日誌? – zerkms
您是否嘗試將上傳目錄設置爲777? –
@LukePittman是的,它沒有奏效。 – xperator