【问题标题】:How to set custom url for loading images on page如何设置自定义 url 以在页面上加载图像
【发布时间】:2021-09-22 08:23:25
【问题描述】:

我已经设置了加载图片的路径:

<img src="{{\Illuminate\Support\Facades\Storage::url($newest->uploaded->where('upf_uploaded_as', 'feature_image')->where('upf_dimension', '200x200')->first()->upf_path)}}" class="card-img-top" alt="">

而且这个基本上是去当前网站域名的URL,打开storage/upload/1399/10/images/{imagename}

但是现在,我需要指定另一个 URL 作为域。所以不要这样:

http://currentwebsite.com/storage/upload/1399/10/images/PCVS511-5 (1).jpg

这将加载图像:

http://differentwebsite.com/storage/upload/1399/10/images/PCVS511-5 (1).jpg

所以调用storage/upload/1399/10/images/{imagename}的路径是一样的。只是域名不一样。但我不知道如何为此提供我的自定义 URL。

所以如果你知道,请帮我解决这个问题,因为我真的需要它。

谢谢。

【问题讨论】:

标签: php laravel laravel-8


【解决方案1】:

您可以为存储创建另一个驱动器(在 config/filesystems.php 中找到),其配置与原始驱动器相同,但 url 选项的设置不同:

'other_public' => [
    'driver' => 'local',
    'root' => storage_path('app/public'),
    'url' => 'http://differentwebsite.com/storage',
    'visibility' => 'public',
],

Documentation

【讨论】:

  • 你的意思是config/filesystems.php
  • @cerealikaeme 是的,就是那个。我会把它添加到答案中!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-05
  • 1970-01-01
相关资源
最近更新 更多