Reputation: 191
I am having trouble displaying images from my db, when i show it without the header i get the image data but when i give it the header('Content-type: image/jpeg');
nothing is displayed.
in my db i have the image column as a longblob.
$host='******';
$user='******';
$pass='******';
$db='******';
$tbl_name='******';
//connect to db
mysql_connect($host, $user, $pass);
mysql_select_db($db);
$id=addslashes($_REQUEST['id']);
$image=mysql_query("SELECT * FROM $tbl_name WHERE id='$id'");
$image=mysql_fetch_assoc($image);
$image=$image['image'];
header('Content-type: image/jpeg');
echo "<img src='$image' />";
?>`
Upvotes: 0
Views: 374
Reputation: 449803
Remove the img
tag. You want to output the raw data only:
echo $image;
Note that addslashes()
is not adequate protection against SQL injection. You would have to use mysql_real_escape_string()
(or intval()
).
Upvotes: 3