473,324 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

retrieving image from mysql

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
1 1523
MarkoKlacar
296 Expert 100+
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

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

Similar topics

0
by: Sreesekhar Palaparthy | last post by:
I used mysql_real_escape_string() method to insert image file into database. Now how do icheck whether it got stored in proper format ?? I used SELECT * INTO OUTFILE F1 FROM IMGTABLE; ...
0
by: Franz Klein | last post by:
Hi Thanks to everybody who told me how to store a BMP image as a BLOB using the LOAD_FILE. Now I would like to now if there is a function that does the opposite to LOAD_FILE? I have tried...
0
by: Franz Klein | last post by:
Hi Thanks to everybody who told me how to store a BMP image as a BLOB using the LOAD_FILE. Now I would like to now if there is a function that does the opposite to LOAD_FILE? I have tried...
2
by: shivapadma | last post by:
i have inserted the image into database using the following code String driverName = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/"; String dbName =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.