du8980919 2019-05-25 19:54
浏览 82

通过ajax上传文件时无法打开流

I have a laravel app in production DigitalOcean VPS with ubuntu and LEMP , web works perfectly but it seems I can't upload files from my web, when I try to upload image via ajax I get the following error (only in production, local works right):

message fopen(/var/www/luisaldada.com/public/uploads/file-25-05-2019-21-39-MAL-421.jpeg): failed to open stream: Permission denied
exception   ErrorException
file    /var/www/luisaldada.com/vendor/league/flysystem/src/Adapter/Local.php
line    158

This looks like an obvious permission error but I already gave write perm recursively to laravel storage folder, I'm using laravel public/local disk to upload files into an upload folder inside public.

filesystems config file:

'public' => [
            'driver' => 'local',
            'root' => public_path(),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

Maybe it has something to do with public folder not having correct permissions to upload/write?

This are my permisions for laravel folder, as you can see I have gone as far as to set ACL for storage folder.

https://i.imgur.com/LLYIECc.png

This is how I upload file in contrller just in case:

$file = $request->file($name);
        $filename = 'file-'.Carbon::now()->format('d-m-Y-H-i').'-'.str_random(3).'-'.mt_rand('000','999').'.'.$file->extension();
        $file->storeAs('uploads', $filename);
  • 写回答

1条回答 默认 最新

  • dqp21271 2019-05-25 20:44
    关注

    Okk, after checking uploads folder perms inside public they were: rwx r-x --x, I did a chmod 770 to uploads and now everything works, what do you guys think, I hope I didn't do anything risky.

    I want to show you guys the commands I now use fot setting perms so you can give me your thoughs:

    cd /var/www/luisaldada.com
    sudo chown GabotronES:ww-data /var/www/luisaldada.com
    &&
    find /var/www/luisaldada.com -type d -exec chmod 755 {} \;
    &&
    find /var/www/luisaldada.com -type f -exec chmod 644 {} \;
    &&
    chmod 770 /var/www/luisaldada.com/public/uploads
    &&
    setfacl -Rdm u:www-data:rwx,u:GabotronES:rwx storage bootstrap/cache
    &&
    setfacl -Rm u:www-data:rwx,u:GabotronES:rwx storage bootstrap/cache
    
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探