Link to home
Start Free TrialLog in
Avatar of renstanford
renstanfordFlag for Indonesia

asked on

How to show picture using "base64_decode()"?

I am using "base64_encode()" to store picture in a variable "$image".
I try to show this picture using "base64_decode($image)" but it failed, i don't know why?

anyone know what should i try/use?
Avatar of Raynard7
Raynard7

How were you trying to use the base64_decode?
You need to do this in conjunction with displaying the header - in a php script by itself. called for each image you wish to retreive.
Avatar of renstanford

ASKER

I encode a picture uploaded by user & save to mysql database (text field).
This is the code I used to decode from my database:
~~~~~~~~~~~~~
$result = mysql_query("SELECT userimage FROM photos WHERE id=1");
$image= base64_decode(mysql_result($result,0,"pic"));

header("Content-type: image/jpeg");
echo "Picture:<br /><img src='$image>";
~~~~~~~~~~~~~
It doesn't show my image... how should I?


**Sorry.. this is the correction**

I encode a picture uploaded by user & save to mysql database (text field).
This is the code I used to decode from my database:
~~~~~~~~~~~~~
$result = mysql_query("SELECT userimage FROM photos WHERE id=1");
$image= base64_decode(mysql_result($result,0,"userimage"));

header("Content-type: image/jpeg");
echo "Picture:<br /><img src='$image>";
~~~~~~~~~~~~~
It doesn't show my image... how should I?
ASKER CERTIFIED SOLUTION
Avatar of Raynard7
Raynard7

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the first comment in image.php - means do what you were doing before (obviously you still need to contact the database)

http://www.phpriot.com/d/articles/database/images-in-mysql/page8.html

is a pretty good tutorial that describes how to deal with images in php.