在视图中从存储文件夹中获取图像 - Laravel 5.4

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44943119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:16:01  来源:igfitidea点击:

Get Image from the Storage Folder in View - Laravel 5.4

phplaravellaravel-5.4

提问by Anna Jeanine

I'm trying to show the default.jpg avatar picture in my Laravel 5.4 profile.blade.php.

我正在尝试在我的 Laravel 5.4 中显示 default.jpg 头像图片profile.blade.php

  • I created a link between the public folder and the storage folder with: php artisan storage:link.
  • The file is stored:
  • 我在公共文件夹和存储文件夹之间创建了一个链接:php artisan storage:link
  • 该文件存储在:

enter image description here

在此处输入图片说明

  • I check in the source code of my webpage which showed the src="/public/storage/uploads/avatar/default.jpg"
  • 我检查了我的网页的源代码,它显示了 src="/public/storage/uploads/avatar/default.jpg"

But still no image could be found. Could someone explain to me what I am missing?

但是仍然找不到图像。有人可以向我解释我缺少什么吗?

回答by omadonex

remove publicfrom path and image will be shown if you set correct link

public如果您设置了正确的链接,将显示从路径中删除和图像

回答by Robert

You can use this in the view once the storage link is present:

一旦存在存储链接,您就可以在视图中使用它:

<img src="{{ asset('storage/uploads/avatar/default.jpg') }}" alt="" />

That will generate the full asset url to your image.

这将为您的图像生成完整的资产 URL。

回答by Govind Samrow

You can get file from storage folder directly so you need to create symbolic link between a folder in your storage directory and public directory.

您可以直接从存储文件夹中获取文件,因此您需要在存储目录和公共目录中的文件夹之间创建符号链接。

ln -s path/to/public/storage/uploads/avatar/ /path/to/laravel/public/avatar

Then you will able to get it directly in blade :

然后你就可以直接在blade中获取它:

<img src="{{ asset('/avatar/default.jpg') }}">

回答by Sagar Gautam

Try this one:

试试这个:

     <img src="{{ asset('/storage/app/uploads/avatar/default.jpg') }}">

And, Your /storage/...../default.jpgshould be inside laravel public folder.

并且,您/storage/...../default.jpg应该在 Laravel 公共文件夹中。

回答by Vishal Varshney

remove public from the path src="/public/storage/uploads/avatar/default.jpg"

从路径中删除 public src="/public/storage/uploads/avatar/default.jpg"