i want to print a image by using a img tag which src is a php file, the script will also process some action at server scirpt. Anyone have an example code?
here is my test code but no effect
img.html
<img src="visitImg.php" />
visitImg.php
<?
header('Content-Type: image/jpeg');
echo "<img src=\"btn_search_eng.jpg\" />";
?>
Use readfile:
<?php
header('Content-Type: image/jpeg');
readfile('btn_search_eng.jpg');
?>
If you are going to use header('Content-Type: image/jpeg');
at the top of your script, then the output of your script had better be a JPEG image! In your current example, you are specifying an image content type and then providing HTML output.
What you're echoing is HTML, not the binary data needed to generate a JPEG image. To get that, you'll need to either read an external file or generate a file using PHP's image manipulation functions.
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