Laravel - How get images from /storage

杀马特。学长 韩版系。学妹 提交于 2019-12-24 00:26:18

问题


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


回答1:


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="">



回答2:


Try to do as

src="storage/images/image01.png"




回答3:


Try

<img src="{{ url('storage'.$images[0]->image)) }}" />


来源:https://stackoverflow.com/questions/44882645/laravel-how-get-images-from-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!