douyan8070 2017-11-16 19:10
浏览 295
已采纳

无法在目录Laravel中写入

In my server, I get this error message

Unable to write in the "/home/company/blog/public/img" directory

When I try to upload an image like this in my controller

$file = $request->file('img');
        $name = time() . '-' . $file->getClientOriginalName();
        $file->move(public_path() .'/img/', $name);
        $company = company::where('username', $username)->first();
        $company->images()->create(['path' => "/{$name}"]);

I know it's about granting permissions I tried

chmod 755 /home/company/blog/public/img

But it still doesn't work.

How can I resolve this?

  • 写回答

1条回答 默认 最新

  • dongyanghan0556 2017-11-16 19:28
    关注

    This is a common case when your server uses different user than you use in console. You can have www-data for web server and user for console.

    755 means full rights for owner and read+execute for the user's group and others (read this). So, when you chmod 755 as user, you grant full access for user and no write permission to www-data.

    You have to change owner of the directory to your server's user. If your server's user is www-data, use

    sudo chown -R www-data:www-data /home/company/blog/public/img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,