Hi I saved a jpg image in BLOB format in mysql. I am having problem rendering the image using PHP onto my view page. When I use
header('Content-type: image/jpeg')
it gives a message on my page as Image cannot be displayed because it contains errors. When I print without header function is displays me some garbage text. Here is my code :
function loadImage(){
//connect to db
mysql_select_db('aaa',$conn);
$query = mysql_query("SELECT * FROM asdf WHERE UserName='".$userName.");
$row = mysql_fetch_array($query);
$content = $row['ProfileImage'];
header('Content-type: image/jpeg');
echo $content;
}
Here is the html code :
<img src='loadImage.php?func=loadImage' />
If the image is displayed then I plan to use
loadImage.php?func=loadImage?id=number'
But image itself is not displaying. Any help greatly appreciated.
$connto the function otherwise it has no connection as that is outside the scope of the function. Also where are you getting$usernamefrom? The same applies for it.mysql_*functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.