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!! Link to comment https://forums.phpfreaks.com/topic/115341-display-blob-in-htmlphp/ 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'; } ?> Link to comment https://forums.phpfreaks.com/topic/115341-display-blob-in-htmlphp/#findComment-593720 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 Link to comment https://forums.phpfreaks.com/topic/115341-display-blob-in-htmlphp/#findComment-594169 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. Link to comment https://forums.phpfreaks.com/topic/115341-display-blob-in-htmlphp/#findComment-594179 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 Link to comment https://forums.phpfreaks.com/topic/115341-display-blob-in-htmlphp/#findComment-594184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.