【问题标题】:Laravel Storage Private Image AccessLaravel 存储私有镜像访问
【发布时间】:2020-11-28 10:49:05
【问题描述】:

我正在尝试从视图访问存储在公用文件夹之外的图像。我可以像这样在 storage/app/public 文件夹中获取图像

    <img src="storage/imagename.jpg" height="200" width="200">

我在 storage/app/avatar 中有一个头像文件夹,我如何将它放到视图中

【问题讨论】:

  • 您是否运行php artisan storage:linkstorage/publicpublic/storage 之间创建符号链接?
  • 您好,抱歉,我认为我的问题不清楚。我可以访问 storage/app/public 中的公用文件夹,它正在工作。我在 storage/app/avatar 中有一个名为 avatar 的私人文件夹,我该如何访问该文件夹?是的,我运行 php artisan storage:link

标签: laravel


【解决方案1】:

config/filesystems.phplinks 属性中添加以下内容:

'links' => [
    ...
    public_path('avatars') => storage_path('app/avatar'),
],

然后运行php artisan storage:link 来创建链接。

像这样访问它:

<img src="avatars/1.jpg">

或者更好地使用asset方法

<img src="{{ asset('avatars/1.jpg`) }}">

【讨论】:

  • 您好,抱歉,我认为我的问题不清楚。我可以访问 storage/app/public 中的公用文件夹,它正在工作。我在 storage/app/avatar 中有一个名为 avatar 的私人文件夹,我该如何访问该文件夹?您提供的上述解决方案适用于公用文件夹
  • 我已经更新了我的答案,它将在您的公共文件夹中创建一个符号链接,链接到您的头像文件夹,以便您可以访问它
  • 但我不希望公众访问头像文件夹中的图像,它应该只对登录用户可用。您提供的上述答案是否使头像公开可见?
  • 它没有。你的问题不是很清楚,但这里是possible solotuin
  • @rahulvimal 你能解决吗,jewishmoses 的解决方案提供商不适用于 s3 存储桶
猜你喜欢
  • 2021-05-29
  • 2021-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-05
  • 2020-03-20
  • 2017-12-25
相关资源
最近更新 更多