Support the ongoing development of Laravel.io →
Configuration Views Packages
Last updated 2 years ago.
0

I'm not sure about this but you can try.

$fileType = File::type($pathToImage);

$response = Response::make( File::get($pathToImage), 200);

$response->header("Content-Type", $fileType);

return $response;
Last updated 2 years ago.
0

I don't think you can pass the $img object directly, as it's an Intervention\Image object, not image data.

I think you can encode it however, before passing it to your response:

$img = Image::make('tmp/test.jpg');
return Response::make($img->encode('jpg'), 200, ['Content-Type' => 'image/jpeg']);

Good luck!

Last updated 2 years ago.
0

I had the same problem recently.. This works perfectly:

$img = Image::make('tmp/test.jpg');
return $img->response();
Last updated 2 years ago.
0

FYI, in Laravel 5, in your controlller:

$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $path);
finfo_close($finfo);
	
// CSS files return incorrect mime type, so fix this
$path_parts = pathinfo($path);
if ($path_parts['extension'] == "css")
{
    $mime = "text/css";
}
		
$response = response(file_get_contents($path), 200)->header('Content-Type', $mime);

return $response;

this works for me for images, html, js and css

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

phyblack phyblack Joined 29 May 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.