如何从Laravel中的资源获取图像? [英] How to get image from resources in Laravel?

查看:75
本文介绍了如何从Laravel中的资源获取图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将所有用户文件上传到目录:

I upload all user files to directory:

/resources/app/uploads/

我尝试通过完整路径获取图像:

I try to get image by full path:

http://localhost/resources/app/uploads/e00bdaa62492a320b78b203e2980169c.jpg

但是我得到了错误:

NotFoundHttpException in RouteCollection.php line 161:

如何通过此路径获取图像?

How can I get image by this path?

现在,我尝试对根目录下/public/uploads/中的文件进行升级:

Now I try to uplaod file in directory /public/uploads/ in the root:

$destinationPath = public_path(sprintf("\\uploads\\%s\\", str_random(8)));
$uploaded = Storage::put($destinationPath. $fileName, file_get_contents($file->getRealPath()));

它给了我错误:

Impossible to create the root directory 

推荐答案

您可以在刀片文件中尝试使用此方法. images文件夹位于公用文件夹

You may try this on your blade file. The images folder is located at the public folder

<img src="{{URL::asset('/images/image_name.png')}}" />

对于Laravel的更高版本(上述版本5.7):

For later versions of Laravel (5.7 above):

<img src = "{{ asset('/images/image_name.png') }}" />

这篇关于如何从Laravel中的资源获取图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆