Jump to content

[SOLVED] Cron job to grab a picture from an external site


86Stang

Recommended Posts

Hello All,

 

The company I work for is building a new building and they've installed a camera that snaps a photo every two minutes to capture the progress being made.  The one pic is stored on a server outside of our web server and is over-written with each new snapshot so I'd like to be able to build a cron that grabs the pic every 15 minutes or so and save it to a folder on our web server so we'll have an actual stack of archived photos for posterity sake.  Anyone have a good idea on how I could do this?

just use the file_get_contents command...

 

<?php

$pic_location = "http://your.camera.page/pic.jpg";

file_put_contents('pic.' . date("Ymdhis") . '.jpg', file_get_contents($pic_location));

//or if you don't have php5:
/*
$open = fopen('pic.' . date("YmdHis") . '.jpg', 'wb');
fwrite($open, file_get_contents($pic_location));
fclose($open);
*/

I think I spoke too soon.  I don't have php5 and I'm getting this error:

 

Warning: fopen(pic20080617081322.jpg) [function.fopen]: failed to open stream: Permission denied in /home/mysite/myfolder/pic_grab.php on line 5

 

Here's the code:

 

<?php

$pic_location = "http://my.camera.page/pic.jpg";

$open = fopen('pic.' . date("YmdHis") . '.jpg', 'wb');
fwrite($open, file_get_contents($pic_location));
fclose($open);


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.