Qnuts Posted February 2, 2010 Share Posted February 2, 2010 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'; }?> Quote Link to comment Share on other sites More sharing options...
akitchin Posted February 2, 2010 Share Posted February 2, 2010 i'm not sure if you need the header() in there; in fact, that could throw your script for an error every time if output has already been displayed. Quote Link to comment Share on other sites More sharing options...
Qnuts Posted February 2, 2010 Author Share Posted February 2, 2010 If i take it out it displays it in binary... Quote Link to comment Share on other sites More sharing options...
akitchin Posted February 2, 2010 Share Posted February 2, 2010 are you testing by accessing the script directly, or by using the page that points to it for its img src? Quote Link to comment Share on other sites More sharing options...
Qnuts Posted February 2, 2010 Author Share Posted February 2, 2010 Both... If I look at the page that points to the script it just shows an empty image regardless of the header. If i'm looking at the script that's where it shows the binary if i take out the header. Quote Link to comment Share on other sites More sharing options...
akitchin Posted February 2, 2010 Share Posted February 2, 2010 if you still have the echo $result; line in there, remove that and leave the header() function in to see if that fixes anything. Quote Link to comment Share on other sites More sharing options...
Qnuts Posted February 2, 2010 Author Share Posted February 2, 2010 Nope! Thanks by the way for helping me and prompt reply's, it's greatly appreciated. Quote Link to comment Share on other sites More sharing options...
akitchin Posted February 2, 2010 Share Posted February 2, 2010 it could be that MySQL is limiting the size of the data that's SELECTed. how big is the file that you've stored? Quote Link to comment Share on other sites More sharing options...
Qnuts Posted February 2, 2010 Author Share Posted February 2, 2010 They vary in size but the smallest is 18 kb Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.