Page 1 of 1

Pulling Images out of a BLOB in mySQL

Posted: Tue Sep 07, 2010 2:12 am
by crammy15b
Hi everyone,

I currently have a page uploading images 2 ways. one of which is a thumbnail to a BLOB file in mySQL. I know that this is not always the best way but for this purpose it fits well.

My problem is that I seem to have got the data in to the DB fine but I cant seem to pull it back out..
The code for the page where I want to retrieve it below and the name of the pictures in the mySQL db is thumb. I want the testimage.jpg to be replaced by the image stored as a BLOB.

Thanks in advance for any help.

Code: Select all

<?php
$sql = "SELECT * FROM mydatabase ORDER BY id DESC";
$result = mysql_query($sql) or die (mysql_error());

while($row = mysql_fetch_array($result))
{
$id = $row['id'];
echo "<img src=\"testimage.jpg\" alt=\"\" name=\"image\" width=\"64\" height=\"48\" align=\"left\" id=\"image\" style=\"background-color: #000099\" /><p class=\"newsArticleTxt\"><strong>" . $row['newstitle'] . "</strong><br /><small>" .$row['newscaption'] . "<BR />";

echo "<a href='displaynews.php?id=".$id."'>Read article</a></small></p>><hr>";
}
?> 

Re: Pulling Images out of a BLOB in mySQL

Posted: Tue Sep 07, 2010 5:31 am
by kumanan.c
Hi,

this is one way to display the image using BLOB images

code is:
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("test", $con);
$query=mysql_query("SELECT * FROM gallery",$con);
$row=mysql_fetch_array($query);
// Output image HTTP headers
header('Content-Length: '.strlen($row['imagename']));
header("Content-type: image/jpg");
echo $row['imagename'];
mysql_close($con);
?>

Re: Pulling Images out of a BLOB in mySQL

Posted: Tue Sep 07, 2010 6:10 am
by crammy15b
Thanks Kumana,

can you explain how that would fit in to the code I have pasted above - i think i'm following along but could you show me how it would word in the situation above that I have posted.

Thanks,
Crammy