如何调试PHP move_uploaded_file()以(How to debug move_up

2019-10-22 07:05发布

move_uploaded_file()以不会为我工作了,这是工作的罚款和刚刚停止无章可循。 有我的方式来检查它为什么不工作了? 这是我现在有,但它只返回TRUE或FALSE。

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

我知道路径是100%正确的,该目录是CHMOD 755有什么我可能是做错了?

Answer 1:

也许这将工作:

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!';

      } 


Answer 2:

检查你的错误报告级别(见error_reporting功能)。 你应该得到一个警告,或注意到的更多的描述了一下。

另外,检查用户PHP脚本的运行(通常在服务器的用户,这是nobodywww-data在很多系统,但情况因人而异)拥有该目录。 随着755 ,只有目录的所有者可以写入。



Answer 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).



文章来源: How to debug move_uploaded_file() in PHP