Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

saluei's avatar

jpg File downloaded from server do not open

I have this code to download files from the server

$tt=\File::mimeType($file_path);
//also test this but do not work
//$headers = array('Content-Type' => 'image/jpeg');
$headers = array('Content-Type' => $tt);
return response()->download($file_path, $FileName ,$headers);

in the development server (XAMPP), It is OK jpg file download and opened. but when deploy in production server (IIS) file download but I can not open it. I check the downloaded file header, laravel change file header when downloaded from the server, for .pdf file it is OK and work but .jpg file have this problem

0 likes
3 replies
jlrdw's avatar

Have you done the symlink. Also search some articles like (stackoverflow) and make sure you have iis config correct for laravel.

saluei's avatar

thankyou @jlrdw I change the code to this and the problem solved

$content=base64_encode(file_get_contents($file_path));
$type=\File::mimeType($file_path);
return compact('content','type');

in fact, convert file content to base 64 and send to the client, and in client have some code to create the file, do you know any method to ZIP (compress) base_64 string before sending it to the client

Please or to participate in this conversation.