Laravel - 如何从/存储图像 [英] Laravel - How get images from /storage
问题描述
我有问题要从存储
中获取图片。所以我把文件和图片上传到 storage
。当文件是图像时,我将它上传到 storage / images /
,并且文件正确转到那里。在数据库中,保存这个: /images/image01.png
。
在刀片视图中,我尝试这样做,但没有work:
< img src =<?php echo asset(storage /。$ images [0] - >图像)GT;? />
在html中显示如下:
< img src =http:// localhost:8000 / storage / images / image01.png>
我该如何做?
谢谢
Laravel提供了一些将文件存储到存储路径的功能。
您应该使用:
php artisan存储:链接
您可以看到 storage / app / public /
将被创建。
您必须保存此文件夹中的所有图片。
注意:如果您想在 storage / app中创建新文件夹/ public /
您应该为此文件夹设置755权限
示例: mkdir('storage / app / public / avatar',0755,true)
更新:如果您存储在 storage / app / public / avatar
< img src ={{asset(storage / avatar / img .jpg)}}alt =>
I'm having problems to get images from storage
. So i upload files and images to storage
. When the file is image i upload to storage/images/
and the file goes there right.
In database it saves this: /images/image01.png
.
In blade view i try to do this but doesn't work:
<img src="<?php echo asset("storage/". $images[0]->image)?>" />
In html it shows like this:
<img src="http://localhost:8000/storage/images/image01.png">
How can i do that?
Thank you
Laravel provides some function to store file on storage path.
You should use that:
php artisan storage:link
You can see storage/app/public/
will be created.
You shoud save all image in this folder.
Note: if you want to make new folder in storage/app/public/
you should set 755 permission for this folder
Example: mkdir('storage/app/public/avatar', 0755, true)
Updated:Load in blade like that if you stored in storage/app/public/avatar
<img src="{{asset("storage/avatar/img.jpg")}}" alt="">
这篇关于Laravel - 如何从/存储图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!