danrah Posted December 1, 2006 Share Posted December 1, 2006 I have a BLOB field in MySQL, InnoDB which stores jpeg images.when i want to retrieve data from my code using:echo $row['image']I can see only the binary codes.what should i do?(Images are inserted properly. when i retrieve them with mysql query browser the images are not corrupted) Quote Link to comment Share on other sites More sharing options...
danrah Posted December 1, 2006 Author Share Posted December 1, 2006 i want to use that as a part of my application not using header() function. i.g:echo "hello";echo $row['image'];is this possible? Quote Link to comment Share on other sites More sharing options...
mainewoods Posted December 1, 2006 Share Posted December 1, 2006 you can not directly display images stored in a db in a web page like that. what you have to do is put an image tag like this in the web page:[code]<img src="getimage.php?id=????">[/code]the ???? part above would be replaced by the primary key of the row # in the db that the image is stored in. If you need to determine that at run time, then you have to code it like this:[code]<img src="getimage.php?id=<?php echo $rownum; ?>">[/code]--notice the php code nested in the img tag. $rownum would have to be set somewhere above in the code.--the getimage.php contains code that gets the url passed rownum, opens the db, retrieves the correct row, then does this:[code]header("Content-type: image/jpeg");echo $dbimagefield; //now we echo it[/code]--getimage.php must not output anything except the 2 statements above, even a single excess space before the opening php start tags in that code will cause it to fail.--If you store graphics right in the db itself, you have to go through all kinds of extra hoops to display them on a web page. As well, all the extra hits on the db will slow down the page. That's why it's almost always better to store just the file name of the graphic in the db, and store the graphic as just a normal graphic on the server. 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.