我不明白为什么这不起作用。这应该很容易。
上传.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 - 使用 root 用户在 SSH 中工作。
- 编辑: upload_max_filesize = 2M
- 编辑: post_max_size = 8M
另一件事!上传完成后,我想获取上传文件的绝对路径。(例如/usr/share/nginx/www/pitfax/upload/test.pdf
:)