search

Home  >  Q&A  >  body text

Title rewritten to: Issue with rendering BLOB image

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粉814160988P粉814160988398 days ago688

reply all(2)I'll reply

  • P粉807471604

    P粉8074716042023-11-01 00:48:49

    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 '';

    reply
    0
  • P粉852114752

    P粉8521147522023-11-01 00:32:22

    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

    reply
    0
  • Cancelreply