OK... I have a very simple script called imageview to display an image.
imageview.php
<html>
<body>
<?php
/ An extremely simple script to show a jpeg /
// echo "<img src=\"getfile1.php\">";
// echo "<img src=\"getfile2.php\">";
// echo "<img src=\"getfile3.php\">";
echo "<img src=\"getdbblob.php\">";
?>
</body>
</html>
As you can see, I can uncomment one of four lines to provide the image source. Out of the four, only the first one, getfile1.php works. Shown immediately below.
getfile1.php
<?php
// in this version, we load the file using php image facilities
Header("Content-type: image/jpeg");
$im = @imagecreatefromjpeg ('larry.jpg');
imagejpeg($im,'',100);
ImageDestroy($im);
?>
getfile2.php is listed below. I'd like to know why it doesn't work.
getfile2.php
<?php
$picfilename = "larry.jpg";
$picfile = fopen($picfilename, "r");
$fileContents = fread($picfile, filesize($picfile));
header("Content-Type: image/jpeg");
imagejpeg($filecontents,'',100);
?>
But even more than that, I'd like to know why getfile3.php does not work... because I think it is the same logic required to do a database read.
getfile3.php
<?php
$picfilename = "larry.jpg";
$picfile = fopen($picfilename, "rb");
$fileContents = fread($picfile, filesize($picfile));
header("Content-Type: image/jpeg");
echo $filecontents;
?>
And finally, I'd like to know why getdbblob.php does not work... near as I can tell, it is an identical copy of several examples I've seen floating around the web.
<?php
include 'db.inc'; // contains showerror logic
// open the database and retrieve the record
if (!($dbh=mysql_connect ("localhost",
"wherbert",
"haggis")))
showerror();
if (!mysql_select_db("wherbert_fotoindx",$dbh))
showerror();
// force to a known record for debug purposes
$query = "SELECT thumbnail FROM thumbs
WHERE thumbid = 314";
if (!($result = @ mysql_query ($query, $dbh)))
showerror();
$data = @mysql_fetch_array($result);
$image = $data["thumbnail"];
// $image = stripslashes($image);
if (!empty($image))
{
header("Content-Type: image/jpeg");
echo $image;
}
else
{
echo "Bad poo";
}
?>
SO... I'm stumped... I really want to be doing the DB retrieval. I cannot guarantee that I do not have a bad image in the DB... that is why I want to getfile3.php script to work... same idea, no?
Environment particulars...
Linux 2.4.20
Apache 1.3.27
PHP 4.3.1
MySql 4.0.12
Displaying output on Win 2K, SP2, with IE6.0.2800.1106
TIA