1

I have problem about rendering image in PHP. I use PHP 7.2 on Ubuntu OS. It work in my localhost and some server. but my NEW server give wrong value.

Here my code:

$fname = '/var/images/item.jpg';
$type = 'image/jpeg';
header('Content-Type:'.$type);         
header('Content-Length: ' . filesize($fname));
$img = file_get_contents($fname);
echo $img;

result:

enter image description here

I already installed php7.2-gd

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
her03
  • 152
  • 4
  • 13
  • You do not need gd to stream file contents to the browser. There is no difference with images and any other file. Maybe this answer helps https://stackoverflow.com/questions/4286677/show-image-using-file-get-contents It could be that [filesize](https://www.php.net/manual/en/function.filesize.php) returns something different per OS, see the docs. I think you can omit this – Giso Stallenberg Dec 03 '21 at 21:18

0 Answers0