I’ve written a PHP script to return an image but the browser can’t display the returned one. Would you guys please tell me what’s wrong?
<?php
$file='demo.gif';
if(file_exists($file)){
header('Content-Type:image/jpeg');
header('Content-Transfer-Encoding: base64');
$data=base64_encode(get_file_contents($file));
header('Content-Length: ' . strlen($data));
echo $data;
}
else
echo 'No such file';
?>
Well, you’re telling the browser that the
.giffile is a JPEG.You also typo’d
file_get_contents.