PHP 警告:move_uploaded_file() 无法移动
2022-08-31 00:57:22
我一直在慢慢学习PHP,并找到了其他开发人员发布的有关该主题和解决方案的一系列信息。我正在尝试让一个Android应用程序通过HTTP post将文件上传到PHP服务器。但是,在我的服务器端有些东西不起作用,试图在PHP中写入文件。
下面是 PHP 代码:
// Where the file is going to be placed
$target_path = "/var/www/media2net/uploads/uploads";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']) .
" has been uploaded";
chmod("uploads/" . basename($_FILES['uploadedfile']['name']), 755);
} else {
echo "There was an error uploading the file, please try again!";
echo "filename: " . basename( $_FILES['uploadedfile']['name']);
echo " target_path: " .$target_path;
}
我已经通过检查客户端的wire shark知道http post被正确发送出去,我也确保了我正在编写文件的目录具有正确的权限,并且php安全模式设置为off。
apache2 错误的输出.log文件读取
[Wed Dec 05 09:25:36 2012] [error] [client 74.14.162.250] PHP Warning:
move_uploaded_file(): Unable to move '/tmp/phpVLOnn3' to
'/var/www/media2net/uploads/downloaded_file.png'
in /var/www/media2net/upload.php on line 9
任何有关此问题的帮助或解决此问题的其他方法将不胜感激。