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
https://forums.phpfreaks.com/topic/190704-blob-to-image/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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