Hello Reader's If you have to return a image from PHP page. then you can use the code as written below:-
<?php
// open the file in a binary mode
$name = './img/ok.png';
$fp = fopen($name, 'rb');
// send the right headers
header("Content-Type: image/png");
header("Content-Length: " . filesize($name));
// dump the picture and stop the script
fpassthru($fp);
exit;
?>
Now you just have to remember that you must send a Content-Type header. Also don't leave any white spaces just after or before <?php ?> tags then only it will return image.
0 Comment(s)