0)) { # no pic available! show the offline. $sec = date("s"); if ($sec < 15) $p = "evacard.jpg"; elseif ($sec < 30) $p = "millycard.jpg"; elseif ($sec < 45) $p = "tillycard.jpg"; else $p = "pennycard.jpg"; $path = $DOCUMENT_ROOT . "./images/offline/$p"; } $fp = @fopen($path, "r"); // Can't read $filename.jpg"); if (!$fp) { for ($i=1; $i<=10; $i++) { $fp = @fopen($DOCUMENT_ROOT . "./campics/temp/camb.jpg", "r"); if (!$fp) { for ($n=0; $n<=500; $n++) { $dummy = mt_rand(0,999); } } else break; } $back = 1; } $content = @fread($fp, 102400); if (substr($content, -2) == chr(hexdec("FF")).chr(hexdec("D9"))) { header ("Content-Type: image/jpeg"); print $content; flush(); } else $back=1; @fclose($fp); # write our backup pic! # if (($back == "") and (date("s") == 30)) if ($back == "") { $fp = @fopen($DOCUMENT_ROOT . "./campics/temp/camb.jpg", "w"); if (flock($fp, 2)) { fwrite($fp, $content); flock($fp, 3); fclose($fp); } fclose($fp); } } # live cam: showlive(); exit(); # master variables for our script # how many pics? $numpics = 53576; $numpics = 20999; # how many secs in a day? $daysecs = 86400; # 60 * 60 * 24 # function which outputs any given picture function showpic($folder="0", $filename="00000001") { $path = $DOCUMENT_ROOT . "./cam/$folder/$filename.jpg"; $path = $DOCUMENT_ROOT . "./cam/latest/$folder/$filename.jpg"; $fp = fopen($path, "r") or die(""); // Can't read $filename.jpg"); $content = fread($fp, 102400); if (substr($content, -2) == chr(hexdec("FF")).chr(hexdec("D9"))) { header ("Content-Type: image/jpeg"); print $content; flush(); } fclose($fp); } # work out where we are today! $d = date("d"); $m = date("m"); $y = date("Y"); # find the start of the day $start = mktime(00, 00, 00, $m, $d, $y); $now = time(); # what second are we on right now? $cursec= $now - $start; # what pic does this second relate to? $cursec = round((($now - $start) / $daysecs) * $numpics); # some checking for out of range results... (never hurts does it ;) if ($cursec < 1) $cursec = 1; if ($cursec > $numpics) $cursec = $numpics; # format the pic filename correctly. $folder = intval ($cursec / 1000); $cursec = sprintf("%08s", $cursec); # that's it showpic($folder, $cursec); exit(); ?>