Support the ongoing development of Laravel.io →
Requests Views
Last updated by @driesvints 2 years ago.
0

Hi,

Just tested and it works perfect. So the problem -apparently- doesn't come from your code...

It's just a suggestion, but try the same code with another picture on another browser, and tell us what you then have as reponse...

0

Try also to replace your $header with the following code:

$headers = array(
'Content-Type'=>'image/jpg',
);

Which version of Laravel are you using?

Last updated 10 years ago.
0

Wow, you were fast! Ah ah... Thank you very much for your answer and time!

I tried with IE, Chrome and Firefox and with a new image (.png now) but still the same :( Might be PHP configuration, maybe?

0

Laravel 4.2. Nope, nothing changes. Uff!

Last updated 10 years ago.
0

Also not with the new $headers array?

Mmh, this doesn't look very good... Are you using an apache webserver?

0

No, sadly still the same with the new $headers array.

Yes, I'm using Apache 2.2.29, and PHP 5.3.29. It's the first time this happens to me as well...

0

Can you then check if your server has the mod_headers enabled (Apache module who can modify the HTTP headers). If it's not enabled, try this (on UNIX):

sudo a2enmod headers

(Must have administrator rights)

Last updated 10 years ago.
0

Just asked my hosting provider about mod_headers. I'll write back as soon as they'll answer me! It should be in a few hours... I thank you again for your time!

Last updated 10 years ago.
0

Saluki, mod_headers is ON already.

0

Ok, if it isn't still solved, we will look at the problem from another point of view...

In firefox/chrome, go to the Developer Tools, then switch on the Network Tool and you will be able to see the HTTP response headers from the server... Can you post them?

0

Your code works on my machine and I got this as HTTP response:

Response

Last updated 10 years ago.
0

So strange! I get: HTTP/1.1 200 OK Date: Sun, 21 Dec 2014 13:45:16 GMT Server: LiteSpeed Connection: close Content-Type: text/html Vary: User-Agent Content-Length: 488613

I get a text/html instead of an image/jpeg... checking some PHP settings now... buoh..

0

I'm sorry that I keep you spending your precious time here :(

0

Sorry, just made some extra tests...

Try this one on your machine... It didn't use the Laravel functions, but still correctly download the picture:

Route::get('/down', function()
{
	$img = '../public/images/pic.jpg';
	header("Content-Type: application/force-download");
	header("Content-Length: " .(string)(filesize($img)) );

	echo file_get_contents($img);
	die();
});
0

Uhm, I get the following error with your new code:

[2014-12-21 17:28:46] production.ERROR: exception 'ErrorException' with message 'Cannot modify header information - headers already sent by (output started at /home/user/laravel/app/routes.php:1)' in /home/user/laravel/app/routes.php:3139
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleError(2, 'Cannot modify h...', '/home/user/...', 3139, Array)
#1 /home/user/laravel/app/routes.php(3139): header('Content-Type: a...')
0

Ok,

Can you print out your routes.php file? the problem is perhaps there...

The error you got indicates that output has already been sent to the browser and this should not be happen there.

Last updated 10 years ago.
0

I'm sorry for my late answer. You're the man, Saluki! :D I deleted everything in my routes.php file except for the Response::download code, and it works!! So, there must be a problem somewhere in my 3147 lines of code, ah ah....

Thank you so much for your time!

0

Apparently, "<?php" and "?>" tags were preceded by some spaces and tabs (I'm wondering why I didn't see that) which caused the header error. Grrrr... now it works just perfectly! :)

It was really kind of you to help me, Saluki.

0

Haha, such a little error... Glad to see that your problem is finally solved :)

Happy coding...

0

Sign in to participate in this thread!

Eventy

Your banner here too?

ndrbdo ndrbdo Joined 21 Dec 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.