0

I'm trying to call some images to some views but ther server doesn't send the images.

Here's how i call my images:

<img src="{{ asset('img/'.$vehicle->pic) }}" alt="{{ $vehicle->model }}">

My images are at:

images

This is what i response i get:

server response

UPDATE 1 Here are the headers of a image: headers

Why is this happening?

Jonathan Solorzano
  • 6,812
  • 20
  • 70
  • 131
  • Do you have any GET endpoint called "img"? Have you tried "chmod -R 777 imgs/" (don't use this in production)? What error do you get if you try to access http://localhost:8000/img/sedan.jpg directly? – Jhuliano Moreno Nov 11 '15 at 03:47
  • I'm in windows, no i don't have any route "img" – Jonathan Solorzano Nov 11 '15 at 03:50
  • Have you defined a default catch-all route (ie `/*`)? If not, you'll only be able to make HTTP requests to the routes you explicitly define. – Evan Plaice Nov 11 '15 at 03:55
  • @JonathanS. the 8000 port seems like you are using homestead, if that is right you should do vagrant ssh and try the chmod command. What http statu code do you get when you go to localhost::8000/img/sedan.jpg ? – Jhuliano Moreno Nov 11 '15 at 03:58
  • See http://stackoverflow.com/a/13297541/290340 to see how to define a catch-all route. Make sure you define this after your other routes or it'll override them. – Evan Plaice Nov 11 '15 at 03:58
  • @EvanPlaice i haven't defined such i thing. – Jonathan Solorzano Nov 11 '15 at 03:59
  • @JhulianoMoreno I'm not using homestead – Jonathan Solorzano Nov 11 '15 at 03:59
  • @JonathanS. what about the status code? 403? 404? 500? – Jhuliano Moreno Nov 11 '15 at 04:00
  • @JonathanS. Unless you prefer to define individual routes for all of your asset directories (ex /img, /styles, etc...) you'll need to. – Evan Plaice Nov 11 '15 at 04:01
  • @EvanPlaice so you want me to define a route to `/*`? what will the func contain? – Jonathan Solorzano Nov 11 '15 at 04:01
  • @EvanPlaice are you sure about that? I have never used such a thing in Laravel 5 and I can load anything in my /public/ folder. NGinx should handle that. – Jhuliano Moreno Nov 11 '15 at 04:02
  • @JhulianoMoreno Status Code: 200 OK, but when i check the resources the image's MIME Types are: `application/x-gzip` and File Size: 0B, but int network tab it says it's downloaded. – Jonathan Solorzano Nov 11 '15 at 04:05
  • @JhulianoMoreno Oh, right... I'm used to Node where the back-end doesn't sit on top of a separate HTTP server layer. Then the asset matching route should be defined in the nginx config. – Evan Plaice Nov 11 '15 at 04:09
  • @JonathanS. that is pretty weird, seems like a misconfiguration in the webserver. What if you add other files with a different extension like .csv, .css or .js in that same /img/ folder, do you get the same 200 empty response or the actual file? Do your files from CSS load correctly? If yes try adding a .jpg file to the /css/ folder and see if you get the correct response. – Jhuliano Moreno Nov 11 '15 at 04:10
  • @JhulianoMoreno In fact, with the css i get a console error: `Resource interpreted as Stylesheet but transferred with MIME type application/x-gzip: "http://localhost:8000/css/app.css".` – Jonathan Solorzano Nov 11 '15 at 04:16
  • @JhulianoMoreno tried moving them to `css` folder, but no luck... – Jonathan Solorzano Nov 11 '15 at 04:19
  • @JonathanS. ok so the problem is within your webserver and has nothing to do with Laravel. I would recommend that you check the configurations and/or try restarting it. Also try to get some help at http://serverfault.com/ . I guess I wont be able to help you for today, sorry. – Jhuliano Moreno Nov 11 '15 at 04:21
  • One last thing you could try is going to /img/a-file-that-doesnt-exist.jpg and see if you get a 404, which you should if the webserver is configured correctly. My best guess would be checking the .htacess and sites-available (or httpd.conf). – Jhuliano Moreno Nov 11 '15 at 04:25
  • @JhulianoMoreno I'm using laravel's built-in web server with `php artisan serve` – Jonathan Solorzano Nov 11 '15 at 04:26
  • @JonathanS. oh! To be honest I didn't even know that existed! TIL something new :). Anyways, I know this if off-topic, I would highly recommend that you use Vagrant + Homestead. Will leave this for someone else with more experience in this matter. – Jhuliano Moreno Nov 11 '15 at 04:37
  • 1
    is the image file corrupted? Try to open it directly from file explorer to check it. – manix Nov 11 '15 at 05:47

0 Answers0