Laravel 5.4->禁止在具有“公共"可见性的存储中的文件上使用403 [英] Laravel 5.4 --> forbidden 403 on files in Storage with 'public' visibility

查看:188
本文介绍了Laravel 5.4->禁止在具有“公共"可见性的存储中的文件上使用403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Laravel和Storage类上遇到了问题.

I have been getting an issue with Laravel and the Storage class.

我已经创建了一个上传表单,供用户控制其帐户中用作徽标的图像.我使用Laravel 文件存储,其灵感来自

I have create an upload form for users to control images used as logos in their account. I use Laravel File Storage inspired by Flysystem .

保存图像时,请按照以下步骤操作:

When I save an image, I proceed as follows :

// Store the logo in the public filesystem, and define a 'public' visibility

$logo = $request->file('logo')->store('logos/'.$account->id, 'public');

// Save the path in the database

$account->update([
  'logo' => $logo
]);

上传正常,我可以在适当的文件结构下找到上传的图片:storage\app\public\logos\1\automatic-filename.jpeg

The upload works fine, I can find the uploaded picture under the appropriate file structure : storage\app\public\logos\1\automatic-filename.jpeg

在我看来,我按如下方式检索图像网址:

In my view, I retrieve the image url as follows :

<img src="{{ Storage::disk('public')->url($account->logo) }}" />

哪个给我正确的路径: http://www.example.com/storage/logos/1/automatic-filename.jpeg

Which gives me the correct path : http://www.example.com/storage/logos/1/automatic-filename.jpeg

但是无论我怎样尝试,图像上都会显示403

But no matter what I try, I get a 403 on the image

禁止 您无权访问此服务器上的/storage/logos/1/automatic-filename.jpeg.

Forbidden You don't have permission to access /storage/logos/1/automatic-filename.jpeg on this server.

我认为我已经正确地完成了所有事情:

I think I have done everything correctly :

  • 我已经使用php artisan storage:link

上载的文件以755权限保存在服务器上.所有相关的文件夹都具有相同的权限.

uploaded files are saved on the server, with a 755 permission. All concerned folders have the same permissions.

我真的不知道在哪里...

I really don't know where to look...

如果有人遇到类似问题,请先谢谢您的投入!

If anyone ever got a similar issue, thanks in advance for your input !

最诚挚的问候,

弗拉德

推荐答案

/public内部运行:

chown -R username:group storage

当然,将username:group替换为在public文件夹中运行ls -l时针对任何其他公共文件或文件夹找到的同一username:group组合.

Of course replace username:group with the same username:group combo that you find against any other public file or folder when you run ls -l whilst in the public folder.

这篇关于Laravel 5.4-&gt;禁止在具有“公共"可见性的存储中的文件上使用403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆