habib009pk Posted September 29, 2009 Share Posted September 29, 2009 Dear Friends I have an image with live live address of that image, I want to download that image when i click on any link for that image, but the problem is that when i click on the link the image has been opened in another window. kindly helps me for that when i clicked on any link then image will be download on my specific location Waiting for your replies Thanks Quote Link to comment https://forums.phpfreaks.com/topic/175926-image-downlaoding-code/ Share on other sites More sharing options...
eatfishy Posted September 29, 2009 Share Posted September 29, 2009 It sounds more like a PC help than coding. Why can't you right click on the link and do SAVE IMAGE AS ? This will download the file for you to the location you want. Quote Link to comment https://forums.phpfreaks.com/topic/175926-image-downlaoding-code/#findComment-927132 Share on other sites More sharing options...
lemmin Posted September 29, 2009 Share Posted September 29, 2009 I think you could do this by setting up a mod rewrite to redirect .jpg (or whatever image extension) to a php file that sets the header to "application/x-www-form-urlencoded" or something that would be downloaded.Then, draw the image using imagejpeg or something. The browser will want to download the file as whatever the basename in the url is, so you would want to dynamically generate that. Quote Link to comment https://forums.phpfreaks.com/topic/175926-image-downlaoding-code/#findComment-927218 Share on other sites More sharing options...
mikesta707 Posted September 29, 2009 Share Posted September 29, 2009 You are talking about forcing the download dialog box right? check out this page Quote Link to comment https://forums.phpfreaks.com/topic/175926-image-downlaoding-code/#findComment-927221 Share on other sites More sharing options...
Alex Posted September 29, 2009 Share Posted September 29, 2009 You can do force downloading with PHP like mikesta707 stated, but you can also do it with .htaccess: <Files *.jpg> ForceType application/octet-stream Header set Content-Disposition attachment </Files> Quote Link to comment https://forums.phpfreaks.com/topic/175926-image-downlaoding-code/#findComment-927222 Share on other sites More sharing options...
habib009pk Posted September 30, 2009 Author Share Posted September 30, 2009 I got the result from this code. //Get the Query String $file=$_SERVER["QUERY_STRING"]; //Get the values from Query String $bidno=$_GET['bid']; $picno=$_GET['npic']; $auct_id=$_GET['auct_id']; //Cut five Character of Query String $file=substr($file, 5, 2000); $filename=$auct_id."_".$bidno."_".$picno.".jpg"; //Display the Save Box header("Content-Type: application/octet-stream;"); header("Content-Transfer-Encoding: binary"); header('Content-Disposition: attachment; filename='.$filename.''); readfile($file); Quote Link to comment https://forums.phpfreaks.com/topic/175926-image-downlaoding-code/#findComment-927526 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.