PHP警告:move_uploaded_file()无法移动

前端之家收集整理的这篇文章主要介绍了PHP警告:move_uploaded_file()无法移动前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在慢慢地学习 PHP,并且发现了一系列关于其他开发者发布的主题解决方案的信息.我试图让一个 Android应用程序通过HTTP post将文件上传PHP服务器.但是,我的服务器端尝试在PHP中写入文件时无法正常工作.

以下是PHP代码

  1. // Where the file is going to be placed
  2. $target_path = "/var/www/media2net/uploads/uploads";
  3.  
  4. /* Add the original filename to our target path.
  5. Result is "uploads/filename.extension" */
  6. $target_path = $target_path . basename($_FILES['uploadedfile']['name']);
  7.  
  8. if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$target_path)) {
  9. echo "The file ". basename( $_FILES['uploadedfile']['name']) .
  10. " has been uploaded";
  11. chmod("uploads/" . basename($_FILES['uploadedfile']['name']),755);
  12. } else {
  13. echo "There was an error uploading the file,please try again!";
  14. echo "filename: " . basename( $_FILES['uploadedfile']['name']);
  15. echo " target_path: " .$target_path;
  16. }

我已经从客户端检查线鲨知道http发送正确,我也确保我正在写文件的目录具有正确的权限,并且PHP安全模式被设置为关闭.

apache2的输出错误.log文件读取

  1. [Wed Dec 05 09:25:36 2012] [error] [client 74.14.162.250] PHP Warning:
  2. move_uploaded_file(): Unable to move '/tmp/PHPVLOnn3' to
  3. '/var/www/media2net/uploads/downloaded_file.png'
  4. in /var/www/media2net/upload.PHP on line 9

任何帮助这个问题或进一步的方式来麻烦拍摄这将不胜感激.

更改/ var / www / media2net / uploads的上传权限,或者通过更改所有者“chown”或“chmod”

例子

  1. $sudo chown apache:apache /var/www/media2net/uploads/
  2. $sudo chmod 755 /var/www/media2net/uploads/

另外,如果downloads_file.png已经存在于该目录中,并且由另一个用户拥有,那么您还需要更改该文件的所有权.

  1. $sudo chown apache:apache /var/www/media2net/uploads/downloaded_file.png

这样,它可以被Apache成功覆盖.

猜你在找的PHP相关文章