huntrguy102 Posted April 5, 2010 Share Posted April 5, 2010 I have images stored in a mysql database. I have it as Type: Blob. It is binary data. my first question is: Did I go about putting the image in right? My second question is: How would I go about retrieving these images from the database? a very detailed explanation would be appreciated because I am basically lost at this point. Thanks. Link to comment https://forums.phpfreaks.com/topic/197664-retrieving-images-from-a-mysql-database/ Share on other sites More sharing options...
ignace Posted April 5, 2010 Share Posted April 5, 2010 Did I go about putting the image in right? Yes. How would I go about retrieving these images from the database? <img src="images.php?image_id=<id>" width="<width>" height="<height>"> images.php must echo out the contents of the BLOB field Link to comment https://forums.phpfreaks.com/topic/197664-retrieving-images-from-a-mysql-database/#findComment-1037403 Share on other sites More sharing options...
huntrguy102 Posted April 6, 2010 Author Share Posted April 6, 2010 And what about the <id>, what do I do with that? Link to comment https://forums.phpfreaks.com/topic/197664-retrieving-images-from-a-mysql-database/#findComment-1037796 Share on other sites More sharing options...
huntrguy102 Posted April 6, 2010 Author Share Posted April 6, 2010 ok this is the code for image.php <?php $conn = mysql_connect('localhost,'username','password') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('database',$conn) or trigger_error("SQL", E_USER_ERROR); //table name is books $sql = "SELECT * FROM books ORDER BY id LIMIT 2"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); //the field with the binary dat is called image $image = $row['image']; header("Content-type: image/jpg"); // or whatever print $image; exit; ?> is this correct? when I look at this php in the browser, it gives me a bunch of random symbols and letters and numbers. Is that supposed to happen? Link to comment https://forums.phpfreaks.com/topic/197664-retrieving-images-from-a-mysql-database/#findComment-1037932 Share on other sites More sharing options...
huntrguy102 Posted April 13, 2010 Author Share Posted April 13, 2010 any help would be appreciated Link to comment https://forums.phpfreaks.com/topic/197664-retrieving-images-from-a-mysql-database/#findComment-1040993 Share on other sites More sharing options...
fenway Posted April 17, 2010 Share Posted April 17, 2010 Then you're still printing another header somewhere. Link to comment https://forums.phpfreaks.com/topic/197664-retrieving-images-from-a-mysql-database/#findComment-1043718 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.