retrieving image from mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gubbachchi
    New Member
    • Jan 2008
    • 59

    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($sq l);
    $values = mysql_fetch_arr ay($result);

    $db_img = $values['frnd_photo'];
    $db_img = base64_decode($ db_img);
    $db_img = imagecreatefrom string($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.g if'));
    fclose($handle) ;

    $img = base64_encode($ img);
    $sql = "insert into photos values(1,6,'nan i',6,'$img')";
    $result = mysql_query($sq l);

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

    With regards
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    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 imagecreatefrom gif .

    Hope this helped.

    Comment

    Working...