DKDiveDude Posted April 2, 2007 Share Posted April 2, 2007 I am trying to display a gif image, part of an image verification on a form conecealing the location of the gif file, on a php webpage, but along with other objects especially plain HTML (text). The following code saved in a file displays the image fine. <? header("Content-type: image/gif"); readfile("image.gif"); ?> However as soon as I add some text like this it stops working, why? Yes I know it must have something to do with the dreaded header I suspect I have to add the html <img> tag somehow. <html><body> Gif image test using php function readfile() <? header("Content-type: image/gif"); readfile("cgi/verification/1.gif"); ?> </body></html> Link to comment https://forums.phpfreaks.com/topic/45284-how-to-display-a-gif-image-on-a-webpage-along-with-text-with-the-readfile/ Share on other sites More sharing options...
trq Posted April 2, 2007 Share Posted April 2, 2007 The easiest way is to include this.... <?php if (isset($_GET['img'])) { header("Content-type: image/gif"); readfile($_GET['img']); } ?> in another file. Then use <img src="thefileabove.php?img=image.gif"> in the calling file. Link to comment https://forums.phpfreaks.com/topic/45284-how-to-display-a-gif-image-on-a-webpage-along-with-text-with-the-readfile/#findComment-219883 Share on other sites More sharing options...
DKDiveDude Posted April 2, 2007 Author Share Posted April 2, 2007 The easiest way is to include this.... <?php if (isset($_GET['img'])) { header("Content-type: image/gif"); readfile($_GET['img']); } ?> in another file. Then use <img src="thefileabove.php?img=image.gif"> in the calling file. Yes I reached same solution, however it displays the correct image place holder size "RED X" but no image. I did it simpler just to test: <? header("Content-type: image/gif"); readfile("cgi/verification/1.gif"); ?> Save the above in a test file "test.php" and then use from other PHP or HTML file like this: echo '<img src="test.php"></img>'; What am I missing? Link to comment https://forums.phpfreaks.com/topic/45284-how-to-display-a-gif-image-on-a-webpage-along-with-text-with-the-readfile/#findComment-219920 Share on other sites More sharing options...
Barand Posted April 2, 2007 Share Posted April 2, 2007 How about :: myimage.php :: <?php $name=$_GET['file']; $im = imagecreatefromgif ("cgi/verification/$name.gif"); header("Content-type: image/gif"); imagegif($im); imagedestroy($im); ?> Then <img src='myimage.php?file=1'> Link to comment https://forums.phpfreaks.com/topic/45284-how-to-display-a-gif-image-on-a-webpage-along-with-text-with-the-readfile/#findComment-220044 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.