Title rewritten to: Issue with rendering BLOB image
P粉814160988
P粉814160988 2023-10-31 08:54:55
0
2
674

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.

P粉814160988
P粉814160988

reply all(2)
P粉807471604

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

echo '';
P粉852114752

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template