Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Broken image with readfile and file_get_contents

I'm trying to use a function in order to get this working:

<img src='login.php?image=ind_legend.jpg'>

But I can't pass through the function to place the image. I went back a couple of steps and tried only this part of the code:

<?php
$file = "http://localhost/sales/test.jpg";
header('Content-type: image/jpeg');
readfile($file);
?>

or using this function:

echo file_get_contents($source);

but the fact is that the only thing I get is a broken image cross (IE) or nothing in Firefox.

I would appreciate any suggestions

Thanks in advance

like image 883
mgv_1513 Avatar asked May 04 '11 00:05

mgv_1513


2 Answers

use the ob_clean() function of php before the readfile()

like image 103
José Luiz Avatar answered Sep 21 '22 16:09

José Luiz


You certainly have some whitespace in your PHP script, or a UTF-8 BOM invisibly before your <?php opening marker. Use a hexeditor to find out.

To debug it further, open the image URL http://localhost/login.php?image=ind_legend.jpg directly in your browser, save the file. And then compare it to the original JPEG.

like image 41
mario Avatar answered Sep 21 '22 16:09

mario