Save an image to my hard drive automatically.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dave_c00
Forum Commoner
Posts: 37
Joined: Wed May 28, 2003 6:08 am

Save an image to my hard drive automatically.

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
dave_c00
Forum Commoner
Posts: 37
Joined: Wed May 28, 2003 6:08 am

Post by dave_c00 »

Ok thanks for you help.

Dave
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

You can possibly bypass PHP by programming Apache (htaccess) to serve these files with the appropriate headers.
Post Reply