Displaying BLOB images from mysql database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Monty
Forum Newbie
Posts: 8
Joined: Sat Jun 18, 2005 10:41 pm

Displaying BLOB images from mysql database

Post by Monty »

Hello

Im trying to load and display a blob image that is stored in the database (in a LONG BLOB field). When using a gui for mysql, i can view the image, so it is stored correctly.
Now i made a php file like this blobdisplay.php:

Code: Select all

<?
$conn = mysql_connect("localhost", "user", "password") 
  OR DIE (mysql_error());
@mysql_select_db ("testdb", $conn) OR DIE (mysql_error());
$sql    = "SELECT * FROM imagetable WHERE image_id=".$_GET["id"];
$result = mysql_query ($sql, $conn);
if (mysql_num_rows ($result)>0) {
  $row = @mysql_fetch_array ($result);
  $image_type = $row["image_type"];
  $image = $row["image"];
  header("Content-type: image/jpeg");
  print $image;
}
?>
Now to display an image i use following code on my page:

Code: Select all

<? echo "<img src='blobdisplay.php?id=18'>"; ?>
18 is the id for the record where the image is stored. Unfortanately a red X shows everytime. Anyone knows what could be the cause for this problem ?


Thanks

Monty
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Just for a test. Navigate to http://yourdoamin.com/blobdisplay.php?id=18 to see what went wrong. Guessing an error caused output here...
Monty
Forum Newbie
Posts: 8
Joined: Sat Jun 18, 2005 10:41 pm

Post by Monty »

d11wtq wrote:Just for a test. Navigate to http://yourdoamin.com/blobdisplay.php?id=18 to see what went wrong. Guessing an error caused output here...
When i do that, it just shows an empty page.
Monty
Forum Newbie
Posts: 8
Joined: Sat Jun 18, 2005 10:41 pm

Post by Monty »

d11wtq wrote:Just for a test. Navigate to http://yourdoamin.com/blobdisplay.php?id=18 to see what went wrong. Guessing an error caused output here...
Ow that was a good way to test.
I found the problem now.
Thanx d11wtq
Post Reply