php Laravel 不显示图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31582829/
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
Laravel doesn't show image
提问by Texas
I have this in the view.blade.php
我在 view.blade.php 中有这个
{{HTML::image('resources/views/Folder/Subfolder/Subfolder/Photo/'.$item->Photo)}}
$item->Photo
takes the image name from the database
$item->Photo
从数据库中获取图像名称
In the same view I have use HTML;
在同样的观点我有 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">
如果我替换 {{HTML::image....
为<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
在屏幕上我看不到<img src="http://localhost:8000/resources/Folder/Subfolder/Subfolder/Photo/3da0d12d6d8667963392a446262b1773.jpg">
照片
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?
图片存在,我把它放在文件夹中。我做错了什么,我只是不知道是什么。我在想 Laravel 想要图片放在特定的文件夹中......这可能是问题的原因吗?你有什么想法?
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...
图片大小为 7.673 字节。我尝试了其他图像,它也不起作用。就像某些东西阻止我的所有浏览器在本地主机上显示图片以前有人遇到过这个问题吗?我不知道我还应该尝试什么...
回答by maytham-???????
In Laravel 5 if you plan to have your images available in public folder, follow this answer:
在 Laravel 5 中,如果您打算将图像放在公共文件夹中,请按照以下答案操作:
Create images
folder under public
folder in Laravel 5.
在 Laravel 5 中的images
文件夹下创建文件public
夹。
Afterward what I do, I use URL::to('/')
to return base URL, then you can added your images folder location like following example:
之后,我使用URL::to('/')
返回基本 URL,然后您可以添加图像文件夹位置,如下例所示:
<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/imagesin local host environment.
{{ URL::to('/images') }}
在本地主机环境中生成http://localhost/images。
and the folder of images location is: your_laravel_project/app/public/images
和图像位置的文件夹是: 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. Hereyou can find in depth info about it.
注意:URL::to('/')
返回基本 URL,它可以以不同的方式使用。在这里您可以找到有关它的深入信息。
Reference: http://laravel.com/api/5.1/Illuminate/Contracts/Routing/UrlGenerator.html#method_to
参考:http: //laravel.com/api/5.1/Illuminate/Contracts/Routing/UrlGenerator.html#method_to
回答by Saugat Thapa
{{ asset("storage/uploads/$notes->file_name")}}
this worked for me. i had file in uploads of storage/app/public folder. tried so many things. turns out its little confusing but awesomely simple once u figure it out. i am in laravel 5.4
这对我有用。我在存储/应用程序/公共文件夹的上传中有文件。尝试了很多东西。原来它有点令人困惑,但一旦你弄清楚它就非常简单。我在 Laravel 5.4
回答by Mas Hary
Show image Laravel 5 if you plan to have your images available in public folder. To display images folder under public folder in Laravel 5 simple:
如果您打算将图像放在公共文件夹中,请显示图像 Laravel 5。要在 Laravel 5 中显示 public 文件夹下的图像文件夹简单:
<img class="img-responsive menu-thumbnails" src="{{ asset($item->photo) }}"/>