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
https://forums.phpfreaks.com/topic/70734-display-picture-from-the-database/
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.';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.