views:

60

answers:

1

Hi.. I want to fetch blob datatype of images from MYSQL database using PHP and these images displayed in Iphone Uiimageview. can anybody post some PHP code to retrieve images from mysql.

Thanks

A: 

Here's an exemplary tutorial: http://forum.codecall.net/php-tutorials/7663-tutorial-storing-images-mysql-php-part-ii-display-your-images.html.

The key is

...
header('Content-type: image/jpg');
echo $content;
...

Note, that the linked tutorial also shows you a good example of an sql injection vulnerability. Before assembling the query try at least something like mysql_real_escape_string().

The MYYN
Grr, `$id = $_GET['id']; ... "SELECT * FROM tbl_images WHERE id='".$id."'"` - yet another sql injection prone php/mysql "tutorial" :( There's minimal error handling for mysql_connect/select_db, but not for the actual query. I'm quite sure there are better tutorials out there...
VolkerK
Thanks, justed skimmed it (obviously) - added note to post about that issue.
The MYYN
Agreed, I think people need to be a little more cautious when posting tutorial solutions, after all the community needs to groom those who are learning and discourage code ridden with security holes. That being said, as long as you have the blob data in your table, the key really is just setting the header and outputting the image data.
webfac
The anti sql injection version of the query can be $id = $_GET['id']; ... sprintf("SELECT * FROM tbl_images WHERE id= '%d'",$id);
Zsolti
thanks.its working.I want to display this image into my Iphone uiimageview using json.plz guide me.
xcodemaddy
consider asking a new question for this -
The MYYN