englishcodemonkey Posted July 18, 2008 Share Posted July 18, 2008 I have loaded an JPEG image into mysqli database called hostajess and in table called images. The binary is in my database but how to I write a php script to retrieve and display the image?? <?php error_reporting(E_ALL); if(isset($_GET['imgid']) && is_numeric($_GET['imgid'])) { require_once('conn.php'); //connected to db $sql = "SELECT image FROM images WHERE imgid=2"; $result = mysqli_query("$sql") or die("Invalid query: " . mysqli_error()); header("Content-type: image/jpeg"); echo mysql_result($result, 0); mysql_close($link); } else { echo 'Please use a real id number'; } ?> My database table is imgid - int image - blob Thanks for any suggestions (by the way i realise using a file system might be easier, but i had less of an idea how to do that!! Quote Link to comment Share on other sites More sharing options...
aseaofflames Posted July 18, 2008 Share Posted July 18, 2008 <?php error_reporting(E_ALL); if(isset($_GET['imgid']) && is_numeric($_GET['imgid'])) { require_once('conn.php'); //connected to db $sql = "SELECT image FROM images WHERE imgid=2"; $result = mysqli_query("$sql") or die("Invalid query: " . mysqli_error()); header("Content-type: image/jpeg"); $im = imagecreatefromstring(mysql_result($result, 0)); imagejpeg($im); imagedestroy($im); mysql_close($link); } else { echo 'Please use a real id number'; } ?> Quote Link to comment Share on other sites More sharing options...
englishcodemonkey Posted July 19, 2008 Author Share Posted July 19, 2008 Ok i have added that code but i still don't see the image? I just see a blank page, no errors or anything?? Thanks Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 19, 2008 Share Posted July 19, 2008 Start by putting both of these lines (you currently only have the second one) after your first opening <?php tag - ini_set ("display_errors", "1"); error_reporting(E_ALL); If you still get a blank page, that probably means you are getting a fatal parse error. You would need to turn on those two settings in php.ini instead to get php to tell you about any parse errors. Next, you are mixing mysqli and mysql function calls (which cannot be done for a single connection or query) and the usage of the mysqli function calls is incorrect. Quote Link to comment Share on other sites More sharing options...
englishcodemonkey Posted July 19, 2008 Author Share Posted July 19, 2008 Thanks for your suggestions! I have added that line of code and I also found i was missing quotes around my id number. You said about the mysql and mysqli functions, which ones are incorrect? I have used mysqli in my other queries which are working well if that matters?? Thanks 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.