Jump to content

Display picture from the database


nicuz

Recommended Posts

I made a script that stores a picture in a database. I have 4 fields in the database: picName, picType, picSize, picture (picture is the field where the picture is actuallu stored; the other fields are self explanatory).

 

What I want is to display the picture on my website. I have my SELECT query but when I try to display the picture using

 

{$row['picture']} 

 

I only get a long list with letters, numbers and strange symbols.

 

I assume that the picture is not displayed like any other text in the database so if you guys could help me I would really appreciate it.

 

Nick

Link to comment
Share on other sites

Tried this and it did not work. I got the "An error occurred" error.

 

$data = $row['picture'];


$data = base64_decode($data);

$im = imagecreatefromstring($data);
if ($im !== false) {
    header('Content-Type: image/jpeg');
    imagejpeg($im);
}
else {
    echo 'An error occurred.';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.