Jump to content

How to display a gif image on a webpage along with text with the readfile()


DKDiveDude

Recommended Posts

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>

 

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.

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?

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'>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.