----- Original Message -----
From: "David Halliday"
Hi,
I am trying to display images in an html page using a
php script.
The output on the screen is bizarre :)
This code works on its own:
<?
$pic = "flower.jpg"
echo file_get_contents ($pic);
?>
the above actually displays the image flower.jpg
without a problem.
But when I include the same script in an html page
the screen is filled with all sorts of characters
Something like this:
<HTML>
<HEAD>
<META http-equiv=Content-Type content="text/jpg;
charset=windows-1252">
</HEAD>
<BODY>
<?
$pic = "flower.jpg"
echo file_get_contents ($pic);
?>
</BODY>
</HTML>
Have tried another charset e.g. "charset=utf-8"
instead of "charset=windows-1252",
but to no avail.
What is the problem? Is there a way of getting the
image to work via php *inside* an html document?
Would greatly appreciate your help!
David
--------------------------
Hello David,
A html document can only contain html. You have to link
to the image as you normal do.
If your image script is called image.php then do it this way -
<html><head></head><body>
<img src="image.php" alt="image">
</body></html>
I you need to identify the image in some way you can pass data with a get
method -
image.php -
<?php
$file = $_GET["file"];
echo(file_get_contents($file);
?>
<html><head></head><body>
<img src="image.php?flower.gif" alt="dynamic image">
</body></html>
The above is just an example and is not a secure way to do this.
Also the image will not display correctly in all browsers unless you send
the correct mime type headers.
Look up header() at php.net
You didn't mention file names so I assume that the extension for the script
is .php or the like. It would be a very bad thing if the script was named
with the extension .jpg or an image type as you server would be parsing all
image files for php script.
Thanks, Rob.