【问题标题】:Server migration troubles with Imagick, Fopen, PHP and PermissionsImagick、Fopen、PHP 和权限的服务器迁移问题
【发布时间】:2014-10-30 07:28:03
【问题描述】:

我最近迁移了 linux 服务器。

我目前在尝试使用 Imagick 从表单上传图片时遇到此错误。

Warning: fopen(/home/user/public/website.com/public/images/users/current/thumb/username.jpg): failed to open stream: Permission denied in /home/user/public/website.com/public/inc/functions/functions.php on line 864

运行的代码驻留在函数中:

try{
    $im = new Imagick($image['tmp_name']);
    if($im_w != 'O' && $im_h != 'O'){
        $im->cropThumbnailImage($im_w,$im_h);
    }

    $fp = fopen($path, 'w'); //the line that is causing the error to occur. line 864.
    $im->writeImageFile($fp);
    return 1;
}
catch(Exception $e)
{
    echo $e->getMessage();
}

我查看了各种 PHP/Linux 权限修复程序,/images/ 目录和子目录当前具有权限:755

谁能帮我解决一下。如果您需要了解其他信息,请发表评论。

提前致谢。

【问题讨论】:

  • 您是否尝试过使用 777,可能是 Web 文件的所有者与尝试写入该目录的所有者不同。我相信 755 只允许文件的所有者写入/编辑,而 777 允许任何用户。
  • 777有什么缺点吗?
  • 不是系统管理员,但据我所知...如果您使用共享主机或允许匿名 FTP,那么 777 不是最好的主意。如果您在专用服务器上,那么您应该没问题。
  • 酷,我在专用服务器上。 :) 谢谢

标签: php linux permissions fopen imagick


【解决方案1】:

只需在我的 linux 命令行中输入命令:

sudo chmod -R 777 /home/username/public/website.com/public/x_images/

【讨论】:

  • 这是一个可怕的人生选择。您允许人们将文件上传到他们可以从中访问文件的地方,并将文件设置为可执行。这意味着您允许人们在您的服务器上运行任意代码。
  • 你有解决办法吗?
猜你喜欢
  • 2018-09-17
  • 1970-01-01
  • 2015-06-16
  • 2011-05-02
  • 2017-11-18
  • 2011-05-17
  • 2021-10-14
  • 2011-01-03
  • 2016-09-05
相关资源
最近更新 更多