从存储文件夹访问图像

时间:2019-05-24 12:53:24

标签: php laravel

我将图像上传到存储文件夹storage / app / public,但我还添加了其他文件夹,以对我来说更有用的方式存储它们

C:\ xampp \ htdocs \ rps \ storage \ app \ public \ images \ user-profile

我设法毫无问题地保存了它们,但是现在我不知道如何在尝试的.blade.php文件中访问它们:

src="storage/images/user-profile/standard/default.png"

C:\ xampp \ htdocs \ rps \ storage \ app \ public \ images \ user-profile \ standard \ default.png

src="storage/images/user-profile/standard/{{$person->avatar}}"

C:\ xampp \ htdocs \ rps \ storage \ app \ public \ images \ user-profile \ standard \ 1558700163.jpg

但这对我不起作用,任何人都可以帮助。我想我的路错了

我还需要添加公用/存储文件夹吗?

1 个答案:

答案 0 :(得分:0)

config/filesystems.php中配置新磁盘,如下所示:

'images' => [
    'driver' => 'local',
    'root' => storage_path('images'),
],

然后获取URL:

$url = Storage::disk('images')->url('file.jpg');

并获取文件内容:

$contents = Storage::disk('images')->get('file.jpg');

您还可以使用storage_path()帮助器。所以在您看来这应该可行:

src="{{storage_path('images/user-profile/standard/default.png')}}"

阅读docs以获得更多信息。

相关问题