By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,348 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,348 IT Pros & Developers. It's quick & easy.

retrieving image from mysql

P: 59
Hi,

I have written a php code to retrieve the image from the mysql database but I am getting the encrypted value. How to convert it into image and display it on the webpage.

Here is the code to retrieve:

$sql = "select photo1 from photos where id='1'";
$result = mysql_query($sql);
$values = mysql_fetch_array($result);

$db_img = $values['frnd_photo'];
$db_img = base64_decode($db_img);
$db_img = imagecreatefromstring($db_img);
echo "$db_img";
***f I print_r($db_img), it will display the encrypted value and echo "$db_img"; line will diplay Resource id #5 as the output


I have used this code to store image:

$handle = fopen("vid.gif", "rb");
$img = fread($handle, filesize('vid.gif'));
fclose($handle);

$img = base64_encode($img);
$sql = "insert into photos values(1,6,'nani',6,'$img')";
$result = mysql_query($sql);

Please help me to solve this issue. I am struggling with this from 2 days.

With regards
Feb 7 '08 #1
Share this Question
Share on Google+
1 Reply


MarkoKlacar
Expert 100+
P: 296
Hi,

Once you have fetched the image from the database and created an image from string you need to copy the image to a new image of the correct type (png, jpg, gif etc) if I remember it correctly.

So you will need to have a look at imagecreatefromgif .

Hope this helped.
Feb 7 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.