Hey. Below is code for a thumbnail.php file that is supposed to display images stored in BLOB format in my database.
I know the upload worked because I see the files with the right sizes in the DB (and also did a manual insert).
I know the script connects and that the query that retrieves the image works, because (if you will look at some of the commented out code) I checked the number of rows it found in the query etc. and it all checked out exactly.
The image is a JPEG file, as I say in the header thingy below. Just so you know, the table 'user_img' has only two columns, id and thumbnail. Thumbnail is the BLOB of the image. And I take that BLOB and echo it out. The script simply gives me this error:
The image “http://akmishra/boosted2/services/thumbnail.php?id=vectorian798” cannot be displayed, because it contains errors.
Someone please help!!!
<?php
$dbhost = 'localhost';
$dbusername = 'xxx';
$dbpasswd = 'xxx';
$database_name = 'xxx';
$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")
or die ("Couldn't connect to server.");
$db = mysql_select_db("$database_name", $connection)
or die("Couldn't select database.");
$username = $_GET['id'];
/*echo $username;
echo '<br><br><br>';*/
?>
<?php
header("Content-type: image/jpg"); // act as a jpg file to browser
$query = "SELECT * FROM user_img WHERE id = '$username'";
$result = mysql_query($query) or die(mysql_error());
/ $num = mysql_num_rows($result);
echo $num;
echo '<br><br><br>';/
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$jpg = $row['thumbnail'];
echo $jpg;
?>