Re: How can I display an image within a script?
| From: | Curt Zirzow | Date: | Wed, 16 Jul 2003 04:05:16 +0000 |
| Subject: | Re: How can I display an image within a script? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-155362@lists.php.net to get a copy of this message | ||
ed@homes2see.com <ed@homes2see.com> wrote:
>
> Yes, the method below would work just fine if you only needed to display
> one image. Trying it on a second image within the same generated page
> would give you a "headers already sent" error.
>
> > [...]
> >
> > So your script will generate html like
> > <img src="/showimage.php?file=filename.jpg">
> >
> > then showimage.php will do something:
> > header('content-type: appropricate/type');
> > // content-length would be good
> > readfile($file);
> >
> > HTH Curt --
it shouldn't perhaps I didn't make it clear enough. You will have two
php scripts. One to output html the other to output images. So you
willl have:
html.php:
<?
$Images = array('file1.jpg', 'file2.jpg');
foreach($Images as $img) {
echo "<img src=\"/showimage.php?file=$img\"><br>";
}
?>
showimage.php
<?
$file = $_GET['file'];
if (file_exists($file) ) {
header('Content-Yype: image/jpeg');
readfile($file);
} else {
header('Content-Yype: text/html');
echo "Error 404";
}
?>