Hi, I have saved jpg image in BLOB format in mysql. I'm having trouble rendering an image to my view page using PHP. When I use
header('Content-type: image/jpeg')
It gives a message on my page that the image cannot be displayed because it contains an error. When I print without the header functionality, some junk text is displayed. This 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; }
This is the html code:
<img src='loadImage.php?func=loadImage' />
If an image is displayed then I intend to use
loadImage.php?func=loadImage?id=number'
But the image itself is not displayed. Any help is greatly appreciated.
Hope this helps someone...
Assuming the image has been uploaded in blob format, then you can use it
First use a query to get the record for which the image is to be displayed and store the blob image in $blobimg
Then use it to convert the blob file
Why the image is saved in the database.
Best practice is to save the image in a folder and give the image a unique name. Then save the image name to the database.
Use
when displaying images