CopyCam
$image_url = "http://dyer.rice.edu/WillRice/images/willrice-webcam.jpg";
$now = date('Y-m-d-Hi') ;
$timeout = 0;
if ( date('Hi') < "0600" || date('Hi') > "1330" ) {
echo "no construction going on right now. it would be useless to capture the image." ;
} else {
set_time_limit(300);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $image_url);
// curl_setopt ($ch, CURLOPT_HEADER, false);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
// GETTING BINARY DATA
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
// SET FILE OUTPUT
$outfile = fopen('./images/willrice-webcam/willrice-webcam-'.$now.'.jpg', 'wb');
curl_setopt($ch, CURLOPT_FILE, $outfile);
// curl_exec($ch);
$image = curl_exec($ch);
// CLOSE CURL AND FILE
fclose($outfile);
curl_close($ch);
// OUTPUT CONFIRMATION
echo "copied ".$image_url." to server. timestamp: ".$now ;
// OUTPUT TO BROWSER OR EMAIL
// header("Content-type: image/jpeg");
// print $image;
// mail('yourself@example.com', 'cron job with CURL completed', '(empty body)');
}