我和Laravel以及 Storage
课程一直有问题 .
我已经为用户创建了一个上传表单,用于控制在其帐户中用作徽标的图像 . 我使用了Flysystem启发的Laravel File Storage .
保存图像时,我按以下步骤操作:
// 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
在我看来,我检索图像网址如下:
<img src="{{ Storage::disk('public')->url($account->logo) }}" />
这给了我正确的道路: http://www.example.com/storage/logos/1/automatic-filename.jpeg
但无论我尝试什么,我都会在图像上得到403
Forbidden You don't have permission to access /storage/logos/1/automatic-filename.jpeg on this server.
我想我已经做好了一切:
-
我创建了从公共/存储到存储/ app / public的符号链接
php artisan storage:link
-
上传的文件以755权限保存在服务器上 . 所有相关文件夹具有相同的权限 .
我真的不知道在哪里看......
如果有人遇到类似问题,请提前感谢您的意见!
最好的祝福,
弗拉德
3 回答
从
/public
内部,运行:当然,在
public
文件夹中运行ls -l
时,使用与任何其他公共文件或文件夹相同的username:group
组合替换username:group
.对所有对我的解决方案感兴趣的人......
我发现Laravel不允许访问这些文件,因为/ storage /是 before 我域名的根目录,它指向/ public!
我将config / filesystem.php公共根路径驱动器更改为public:
原始配置:
修改配置:
现在所有与存储相关的路径都在公共文件夹中......我仍然可以使用方便的存储类!
希望能帮助到你 .
弗拉德
我使用 root 权限创建了
php artisan storage:link
. 因此,用户无法访问/ public / storage / ...目录 .使用命令
ls -l
转到/public
文件夹,您将看到group:owner permissions .chown -h storage yourgroup:yourusername
现在可从浏览器访问目录 .