9

I have this in my 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;, and 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 the following:

<img src="resources/Folder/Subfolder/Subfolder/Photo/{$item->Photo}}" alt="NO PHOTO">

I see this on the screen:

<img src="http://localhost:8000/resources/Folder/Subfolder/Subfolder/Photo/3da0d12d6d8667963392a446262b1773.jpg">

NO PHOTO

The picture exists, I saw it in the folder. I'm doing something wrong, I just don't know what.

I'm thinking that Laravel wants pictures to be in a specific folder... could this be the cause of the problem? Do you have any ideas?

In my controller I have this:

$destinationPath = base_path().'\resources\Folder\Subfolder\Subfolder\Photo';
            chmod($destinationPath,0777);

The picture size is 7.673 bytes. I tried it with another image, and it doesn't work either. It seems that something is preventing all browsers from showing the pictures on localhost.

Has anyone encountered this problem before ? I don't know what else I should try ...

Run_Script
  • 2,487
  • 2
  • 15
  • 30
Texas
  • 443
  • 2
  • 6
  • 17
  • did the above image appeared correctly? the one you are showing using laravel – Rock Rathore Jul 23 '15 at 09:19
  • i see no image, that's the problem – Texas Jul 23 '15 at 09:22
  • Debug url of image in your browser, open it in new tab and see if the path is correct. – Rock Rathore Jul 23 '15 at 09:25
  • I see this in the page source: is that what you want to know > I made a change, now I have this: {!!HTML::image('Photo/'.$item->Photo, 'NO PHOTO', array( 'width' => 200, 'height' => 200))!!} and on the screen I see NO PHOTO – Texas Jul 23 '15 at 09:31

3 Answers3

11

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

Community
  • 1
  • 1
Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
  • This is what I was looking for... i just want to know what URL::to('/') does ? – Texas Jul 23 '15 at 10:38
  • Didnt you advice me on another question to place images in the resources folder ? – Sven van den Boogaart Jul 24 '15 at 21:16
  • @svenb I saw your question and I do not advice you that, I suggest you to protect your images folder but you wanted to find the permission problem, which is fair. If the answer here can be used in your case I will be happy, if not then I think the problem you have had in your question is possible not the same as here. I wanted earlier only to help you with other solution. let me know it is still so I can look at it. – Maytham Fahmi Jul 25 '15 at 09:53
  • how to use in css? – romal tandel Sep 18 '18 at 12:02
2
{{ 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

Saugat Thapa
  • 382
  • 5
  • 23
0

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:

<img class="img-responsive menu-thumbnails" src="{{ asset($item->photo) }}"/>
xlm
  • 6,854
  • 14
  • 53
  • 55
Mas Hary
  • 96
  • 3