我一直在慢慢学习 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 帖子已正确发送,我还确保我正在写入文件的目录具有正确的权限,并且 php 安全模式设置为关闭。
apache2 error.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
对此问题的任何帮助或解决此问题的进一步方法将不胜感激。