Laravel不显示图像 [英] Laravel doesn't show image
问题描述
我在view.blade.php中有这个
{{HTML :: image('resources / views / Folder /Subfolder/Subfolder/Photo/'.$item->Photo)}}
$ item-> Photo
从数据库中获取图像名称
在同一视图中,我有使用HTML;
我在屏幕上看到的是:
< img src =http:// localhost:8000 / resources / Folder / Subfolder / Subfolder / Photo / 3da0d12d6d8667963392a446262b1773.jpg>
如果我替换 {{HTML :: image .... < code
with < img src =resources / Folder / Subfolder / Subfolder / Photo / {$ item-> Photo}}alt =NO PHOTO>
我在屏幕上看到
< img src =http:/ /localhost:8000/resources/Folder/Subfolder/Subfolder/Photo/3da0d12d6d8667963392a446262b1773.jpg\">
无图
图片存在,我播放它在文件夹中。
我做错了什么,我只是不知道。
我在想,Laravel想要将图片放在特定的文件夹中......这可能是问题的原因吗?你有什么想法吗?
在控制器中我有这个:
$ destinationPath = base_path()。'\resources\Folder\Subfolder\Subfolder\Photo';
chmod($ destinationPath,0777);
图片大小为7.673字节。
我尝试过使用其他图片,但它也不起作用。这就像是阻止我的所有浏览器在本地主机上显示图片
有没有人遇到过这个问题?
我不知道还有什么我应该尝试的......
在Laravel 5中,如果您打算让在公共文件夹中可用的图片,请按照下面的回答:
在 public下创建
images
/ code>在Laravel 5中。
然后我使用 URL :: to('/')
来返回基本网址,然后你可以添加你的图片文件夹位置,如下面的例子:
< img src ={{URL :: to('/')}} / images / {{$ item-> Photo}}alt ={{$ item-> Title}}/>
或大括号内的所有内容
< img src ={{URL :: to('/ images /'。$ item->照片)}}alt ={{$ item-> Title }}/>
您不应该向资源文件夹写入权限。
{{URL :: to('/ images')}}
generate http:// localhost / images 。
以及图片位置的文件夹是: your_laravel_project / app / public / images
如果您打算保护您的图片不受公开视图,那么只有经过身份验证的用户才能看到图片,然后点击此链接:
注意: URL :: to('/')
返回基本URL,它可以以不同的方式使用。 这里可以找到关于它的深入信息。
参考: http://laravel.com/api/5.1/Illuminate/Contracts/Routing/UrlGenerator.html#method_to
I have this in the view.blade.php
{{HTML::image('resources/views/Folder/Subfolder/Subfolder/Photo/'.$item->Photo)}}
$item->Photo
takes the image name from the database
In the same view I have use HTML;
What I see on the screen is this:
<img src="http://localhost:8000/resources/Folder/Subfolder/Subfolder/Photo/3da0d12d6d8667963392a446262b1773.jpg">
If I replace {{HTML::image....
with <img src="resources/Folder/Subfolder/Subfolder/Photo/{$item->Photo}}" alt="NO PHOTO">
on the screen I see <img src="http://localhost:8000/resources/Folder/Subfolder/Subfolder/Photo/3da0d12d6d8667963392a446262b1773.jpg">
NO PHOTO
The pictures exists, I sow it in the folder. I'm doing something wrong, I just don't know what. I'm thinking that Laravel wants pictures to be on a specific folder... could this be the cause of the problem? Do you have any ideas?
In controller I have this:
$destinationPath =base_path().'\resources\Folder\Subfolder\Subfolder\Photo';
chmod($destinationPath,0777);
The picture size is 7.673 bytes. I tried with other image, it doesn't work either. It's like something prevents all of my browsers to show pictures on localhost Has anyone encountered this problem before ? I don' know what else I should try...
In Laravel 5 if you plan to have your images available in public folder, follow this answer:
Create images
folder under public
folder in Laravel 5.
Afterward what I do, I use URL::to('/')
to return base URL, then you can added your images folder location like following example:
<img src="{{ URL::to('/') }}/images/{{ $item->Photo }}" alt="{{ $item->Title }}" />
OR all of it inside the braces
<img src="{{ URL::to('/images/' . $item->Photo) }}" alt="{{ $item->Title }}" />
You should not give write permission to resources folder.
{{ URL::to('/images') }}
generate http://localhost/images in local host environment.
and the folder of images location is: your_laravel_project/app/public/images
If you plan to protect your images from public view, so only authenticated user can see the images, then follow this link:
How to protect image from public view in Laravel 5?
Note: URL::to('/')
returns base URL and it can be used different ways. Here you can find in depth info about it.
Reference: http://laravel.com/api/5.1/Illuminate/Contracts/Routing/UrlGenerator.html#method_to
这篇关于Laravel不显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!