Jump to content

Blob to image


Qnuts

Recommended Posts

Hey Ya'll

 

Just wondering how you convert a blob format from a db back into an image using php.  I am trying to display an img that is stored as a blob.

 

This is the img tag

 img style='float:right' width='80px' height='80px' src='image.php?image_id=" . $fldID_ID . "' alt='Photo' />");

 

And this is the file that selects it from the db:

<?php
     // some basic sanity checks
     if(isset($_GET['image_id']) && is_numeric($_GET['image_id'])) {
         //connect to the db
         $link = mysql_connect("localhost", "", "") or die("Could not connect: " . mysql_error());
  
         // select our database
         mysql_select_db("people") or die(mysql_error());
           
           // get the image from the db
        $sql = "SELECT Picture FROM people WHERE ID=" . $_GET['image_id'];
        
         // the result of the query
         $result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
            echo $result;
         // set the header for the image
         header("Content-type: image/jpeg");
                  echo mysql_result($result, 0);
  
        // close the db link
         mysql_close($link);
     }
     else {
         echo 'Please use a real id number';
     }?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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