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?

Link to comment
Share on other sites

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);
*/

Link to comment
Share on other sites

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);


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.