How to debug move_uploaded_file() in PHP

懵懂的女人 提交于 2019-12-24 12:32:06

问题


move_uploaded_file() won't work for me anymore, it was working fine and just stopped out of nowhere. Is there a way for me to check why it's not working anymore? Here's what I currently have, but it only returns TRUE or FALSE.

$status = move_uploaded_file($tempFile, $targetFile);
if($status) {
  echo 'its good';
} else {
  echo 'it failed';
}

I know the path is 100% correct and the directory is CHMOD 755. Is there anything I might be doing wrong?


回答1:


Maybe this will work:

if(!move_uploaded_file($_FILES['attachement']['tmp_name'], $uploadfile)) {

echo 'Your file was not uploaded please try again
here are your debug informations:
'.print_r($_FILES);

      } else {

          echo 'image succesfully uploaded!';

      } 



回答2:


Check your error reporting level (see error_reporting function). You should get a warning or notice that's a bit more descriptive.

Also, check that the user your PHP script runs as (usually the server's user, which is nobody or www-data on a lot of systems, but YMMV) owns the directory. With 755, only the owner of the directory can write to it.




回答3:


Permissions of 755 means that only the owner of the directory can write to that directory.

So the question is, who is the owner and as what user is the web-server / php running?

If they don´t match, you can either change the ownership or the group (also changing the permissions to 775).



来源:https://stackoverflow.com/questions/2908700/how-to-debug-move-uploaded-file-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!