我一直在慢慢地学习
PHP,并且发现了一系列关于其他开发者发布的主题和解决方案的信息.我试图让一个
Android应用程序通过HTTP post将文件上传到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; }
我已经从客户端检查线鲨知道http发送正确,我也确保我正在写文件的目录具有正确的权限,并且PHP安全模式被设置为关闭.
[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
任何帮助这个问题或进一步的方式来麻烦拍摄这将不胜感激.
更改/ var / www / media2net / uploads的上传权限,或者通过更改所有者“chown”或“chmod”
原文链接:https://www.f2er.com/php/139431.html例子
$sudo chown apache:apache /var/www/media2net/uploads/ $sudo chmod 755 /var/www/media2net/uploads/
另外,如果downloads_file.png已经存在于该目录中,并且由另一个用户拥有,那么您还需要更改该文件的所有权.
$sudo chown apache:apache /var/www/media2net/uploads/downloaded_file.png
这样,它可以被Apache成功覆盖.