无法使用move_uploaded_file移动文件php

时间:2017-08-20 19:39:23

标签: php

执行以下代码,我收到此错误:

Warning: move_uploaded_file(/chroot/home/xxxx/public_html/Project/img/uploads/ee9b37faf0390088b3bd4b1eb0d3b862.jpg): failed to open stream: Permission denied in /chroot/home/xxxx/public_html/Project/php/class/edit_profile_form.php on line 101

Warning: move_uploaded_file(): Unable to move '/tmp/phpBXXoJs' to '/chroot/home/xxxx/public_html/Project/img/uploads/ee9b37faf0390088b3bd4b1eb0d3b862.jpg' in /chroot/home/xxxx/public_html/Project/php/class/edit_profile_form.php on line 101

代码:

$target_dir = "/chroot/home/xxxx/public_html/Project/img/uploads/";
$db_target_dir = "/~xxxx/Project/img/uploads/";
$this->target_file = $target_dir . md5($this->username);
$db_target_dir=$db_target_dir.md5($this->username);
$imageFileType = pathinfo($_FILES["photo"]["name"],PATHINFO_EXTENSION);
echo $imageFileType;

if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "PNG" && $imageFileType != "jpeg" && $imageFileType != "gif" ){
        $this->message="Errore: formato not supported";
        return false;
}

$this->target_file=$this->target_file.".".$imageFileType;
$db_target_dir=$db_target_dir.".".$imageFileType;
if ((!move_uploaded_file($_FILES["photo"]["tmp_name"], $this->target_file)) || ($_FILES["photo"]["size"] > 150000)){
        $this->message="Error2";
        return false;
}
$this->target_file=$db_target_dir;

                }

我有权在该文件夹上书写,但我无法弄清楚为什么会遇到这个问题

提前谢谢

1 个答案:

答案 0 :(得分:0)

答案显然是权限。你说有权写入该文件夹,但是用户运行的是什么?

看一下正在创建的临时文件的所有者 - 它会像www-data之类的东西。然后确保此用户具有对目标文件夹的写入权限。