mosh Posted November 22, 2009 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); ?> Your help in appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/182553-retrieve-images-not-just-display-them-on-the-web-page-from-blob/ Share on other sites More sharing options...
premiso Posted November 23, 2009 Share Posted November 23, 2009 Using header's this can be accomplished: 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"); header('Content-Disposition: attachment; filename="image.jpg"'); echo mysql_result($ret, 0); mysql_close($link); ?> Give that a shot and see if it does it how you want, you will have to accept the download. Another option is to save the image as a file on the host then after all files are saved you can zip up that directory etc, but yea hopefully you want to just save it Quote Link to comment https://forums.phpfreaks.com/topic/182553-retrieve-images-not-just-display-them-on-the-web-page-from-blob/#findComment-963654 Share on other sites More sharing options...
mosh Posted November 23, 2009 Author Share Posted November 23, 2009 Thank you. It works. I've found an alternate way of doing it. It's as follows: mysql_select_db("media",$link); $que="select imageBlob from images where imageId=21"; $ret=mysql_query($que)or die("Invalid query: " . mysql_error()); $returned=mysql_result($ret,0,0); $file=fopen("downloadedImage.jpeg","w"); fwrite($file,$returned); Quote Link to comment https://forums.phpfreaks.com/topic/182553-retrieve-images-not-just-display-them-on-the-web-page-from-blob/#findComment-963715 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.