Trying to open a jpeg image in any browser and it won't show, shows a black screen with a small white rectangle in it.

I've tried setting errors display in php.ini and increasing the memory size. The jpg file is only 219 KB.
ini_set('memory_limit', '16M');
ini_set('memory_limit', -1);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
However, no errors pop up and it fails to open on IE, chrome, or firefox. I've also checked under the IIS manager under the MIME.types to check if the extension "jpeg, jpg, jpe" was listed there and they are. Below is my PHP code:
$file = 'test.jpg';
header('Content-type: image/jpeg');
$image = file_get_contents($file);
echo $image;
//readme($file) <-- also fails
Any guidance on this would be greatly appreciated.
I had the same problem, solved this issue by adding below ob clean while loop after header
$file = 'test.jpg';
header('Content-type: image/jpeg');
/*It will clean output buffer*/
while (ob_get_level() && @ob_end_clean()) {
;
}
$image = file_get_contents($file);
echo $image;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With