【问题标题】:Laravel fetch files storage with sub-directoryLaravel 获取带有子目录的文件存储
【发布时间】:2021-10-08 21:17:12
【问题描述】:

在我的 laravel 7.x 应用程序中,所有上传的文件都存储在 storage/app/public/<user-uuid-as-directory>

例如:
storage/app/public/a6d4b3cb-a823-11eb-bfce-fcaa149efd09/72c2881d-a824-11eb-bfce-fcaa149efd09.png

当我尝试访问该文件时,我收到404 错误。

文件系统.php

... 

'images' => [
   'driver'     => 'local',
   'root'       => storage_path('app/public'),
   'url'        => env('APP_URL') . '/images',
   'visibility' => 'public',
],

...

some.blade.php

$uuid = auth()->user()->token; // 'a6d4b3cb-a823-11eb-bfce-fcaa149efd09'

@foreach($images as $image)
    <img src="{{ Storage::disk('images')->url($uuid . '/' . $image) }}" />
@endforeach

我在这里做错什么了..?

【问题讨论】:

  • 尝试在urlfilesystem.php 中将images 更改为storage
  • 同时使用php artisan config:clear清除配置缓存。
  • 试过了,不行。
  • 另外,您是否创建了从 public/storage 到 storage/app/public 的符号链接?
  • 那么可能是权限问题。确保服务器对存储目录及其子目录具有读取权限

标签: php laravel directory storage


【解决方案1】:

我认为您需要创建 symbolic link 然后更改 filesystem.php 文件

'url'=> env('APP_URL') . '/images', 

成为

'url'=> env('APP_URL') . '/storage/images',

希望对你有帮助,谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 2016-02-09
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多