Example #1
0
function getCameraFiles($dir, $CAMID)
{
    $result = array();
    $cdir = scandir($dir);
    foreach ($cdir as $key => $value) {
        if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) {
            if (preg_match("/^\\d{8}\$/", $value)) {
                $result = array_merge($result, getCameraFiles($dir . DIRECTORY_SEPARATOR . $value, $CAMID));
            }
        } else {
            if (strpos($value, $CAMID) !== false) {
                if (preg_match("/(\\d{14}_[^\\.]+)/", $value, $matches)) {
                    $result[$matches[1]] = $dir . DIRECTORY_SEPARATOR . $value;
                }
            }
        }
    }
    ksort($result);
    return $result;
}
 ******************************************************************************/
/******************************************************************************
 * Script clears files uploaded to subfolders of by all defined cameras
 * - newest __KEEP_LAST__ files are not deleted
 * - empty day folders are deleted
 ******************************************************************************/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
error_reporting(0);
// disable error reporting
// update path to config file (cron scripts are usualy outside standard web folder)
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'camera' . DIRECTORY_SEPARATOR . 'cam-cfg.php';
require_once __CAMERA_ROOT__ . DIRECTORY_SEPARATOR . 'cam-utils.php';
foreach ($CAMERAS as $key => $camera) {
    $files = getCameraFiles(__CAMERA_ROOT__, $camera);
    //get list of camera files
    //debug  print_r($files);
    if (count($files) > __KEEP_LAST__) {
        //debug    echo "unlink(".reset($files).");" . PHP_EOL;
        unlink(reset($files));
        for ($ii = 0; $ii < count($files) - __KEEP_LAST__ - 1; ++$ii) {
            //debug      echo "unlink(".next($files).");" . PHP_EOL;
            unlink(next($files));
        }
    }
}
$cdir = scandir(__CAMERA_ROOT__);
foreach ($cdir as $key => $value) {
    if (is_dir(__CAMERA_ROOT__ . DIRECTORY_SEPARATOR . $value)) {
        if (preg_match("/^\\d{8}\$/", $value)) {
Example #3
0
/******************************************************************************
 * Script returns to browser last img from defined camera
 *
 * Params:
 *    cam   index of camera in $CAMERAS array /default is 0/
 ******************************************************************************/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
error_reporting(0);
// disable error reporting
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cam-cfg.php';
require_once __CAMERA_ROOT__ . DIRECTORY_SEPARATOR . 'cam-utils.php';
$dir = __CAMERA_ROOT__;
$CAMID = isset($_GET['cam']) && is_numeric($_GET['cam']) && isset($CAMERAS[$_GET['cam']]) ? $CAMERAS[$_GET['cam']] : $CAMERAS[0];
$files = getCameraFiles($dir, $CAMID);
$last_file = end($files);
/*******
// debug only
print_r($files);
echo "Last file is: <$last_file>";
exit;
*/
// open the file in a binary mode
$fp = fopen($last_file, 'rb');
// send the right headers
header("Content-Type: image/jpg");
header("Content-Length: " . filesize($last_file));
header("Timestamp: " . key($files));
// dump the picture and stop the script
fpassthru($fp);