moshy Posted November 22, 2009 Report Share Posted November 22, 2009 I have stored images on mysql using blob. I want to download the images back to my computer in their original format (Not just displaying them on the web page). How do I do this ? The script for displaying the images on the web page is shown below. How can I modify this code to directly download the images back to my computer ? <?php $link=mysql_connect("localhost","root",""); if(!$link) { die("could not connect:".mysql_error()); } mysql_select_db("media",$link); $que="select imageBlob from images where imageId=10"; //imageBlob- name of the blob data type field in mysql. $ret=mysql_query($que)or die("Invalid query: " . mysql_error()); header("Content-type: image/jpeg"); echo mysql_result($ret, 0); mysql_close($link); ?> Quote Link to comment Share on other sites More sharing options...
cornetofreak Posted November 25, 2009 Report Share Posted November 25, 2009 You should use the force http header commend for content disposition <?php $link=mysql_connect("localhost","root",""); if(!$link) { die("could not connect:".mysql_error()); } mysql_select_db("media",$link); $que="select imageBlob from images where imageId=10"; $ret=mysql_query($que)or die("Invalid query: " . mysql_error()); $data = mysql_result($ret, 0); header("Content-type: image/jpeg"); header('Content-Disposition: attachment; filename="image.jpg"'); header('Content-Length: '.strlen($data)); echo $data; mysql_close($link); ?> should work fine Quote Link to comment Share on other sites More sharing options...
moshy Posted November 27, 2009 Author Report Share Posted November 27, 2009 Thank you ! Quote Link to comment Share on other sites More sharing options...
cornetofreak Posted November 29, 2009 Report Share Posted November 29, 2009 you might want to look into the php zip class that comes in PHP5... this way you can loop all your images and the output a zip file containing your images 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.
Note: Your post will require moderator approval before it will be visible.