Page 1 of 1

Save an image to my hard drive automatically.

Posted: Mon Jan 16, 2006 3:33 am
by dave_c00
Hello,

I would like to save an image from a website to my hard drive automatically using a php script.? Is this possible. I can upload an image automatically to my server but not sure about the other way around.

Thanks

Dave

Posted: Mon Jan 16, 2006 3:41 am
by onion2k
It's not possible. The best you could do is serve the image using a MIME type of "force download"..

Code: Select all

$file = "image.jpg";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"".basename($file)."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($file));
set_time_limit(0);
@readfile($file) or die("File not found.");
The user should be prompted to save the file.. there's no way around that.

Posted: Mon Jan 16, 2006 3:52 am
by dave_c00
Ok thanks for you help.

Dave

Posted: Mon Jan 16, 2006 9:43 am
by Ambush Commander
You can possibly bypass PHP by programming Apache (htaccess) to serve these files with the appropriate headers.