Camera Archive 3

[insert_php]
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Display the most recent images uploaded to a web site directory
// Once displayed the images can be kept or deleted
// Images can be skipped
// Code based on http://stackoverflow.com/questions/3847955/php-display-most-recent-images-from-directory
// Code by Ravi Gupta; started around June 2015
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Ftp directory(s) where camera puts images
$image_locations3 = “lmac.ca/camera3/*”;

// Time Zone http://php.net/manual/en/timezones.php
date_default_timezone_set(‘Canada/Eastern’);

// How many days of images to display and keep, the rest are deleted
$days_of_images = 2 ;

// After displaying $number_of_images are the rest deleted
// Set TRUE or FALSE
$delete = TRUE ;

// Website’s (image location’s) domain name; include sub domains if required
$domain = “lmac.ca”;

// Image file name pattern.
// Motion0001.jpg Motion0002.JPG and so on would be Motion*.{jpg,JPG}
// 2015-06-30.jpg 2016-1-1.JPG and so on would be *.{jpg,JPG}
// Probable image file name extensions jpg, JPG, png, PNG, gif, GIF (case sensitive)
$file_names = “*.{jpg,JPG}”;

// It is unlikely anything below needs to be edited
//////////////////////////////////////////////////////////////////////////////////

// Locations to search
$search3 = $image_locations3.$file_names;

// Get image files from locations in $search
$images3 = glob($search3, GLOB_BRACE);

// Rename files if not following a consistent naming convention
$remove = “_md_”;
for ( $i = 0; $i < count($images3) ; $i++ ) { $image_split = explode($remove , $images3[$i]); if ( $image_split[1] != "") { $old_name = $images3[$i]; $new_name = $image_split[0].$image_split[1]; rename($old_name , $new_name); $images3[$i] = $new_name; } } // Rename files if not following a consistent naming convention $remove = "_chn02"; for ( $i = 0; $i < count($images2) ; $i++ ) { $image_split = explode($remove , $images3[$i]); if ( $image_split[1] != "") { $old_name = $images3[$i]; $new_name = $image_split[0]."_chn0_2".$image_split[1]; rename($old_name , $new_name); $images3[$i] = $new_name; } } // Rename files if not following a consistent naming convention $remove = "_TIMER_MNG_"; for ( $i = 0; $i < count($images2) ; $i++ ) { $image_split = explode($remove , $images2[$i]); if ( $image_split[1] != "") { $old_name = $images3[$i]; $new_name = $image_split[0]."_".$image_split[1]; rename($old_name , $new_name); $images3[$i] = $new_name; } } // Reverse sort, sort descending, newest images first based on file name rsort($images3); // Number of images found $images_counted = count($images3); // Display information on the web page $hours = $days_of_images * 24; echo "
Display limit set to past $hours hours.” ;

// Setting a reference time
$first_image_time = filemtime($images3[0]);

// Setting oldest image time difference in seconds
$max_image_time_difference = $days_of_images * 24 * 3600 ;

// Image display loop
// writes out the HTML code required to show the images
foreach($images3 as $image)
{
$image_time = filemtime($image);
$image_size = filesize($image);
$image_size_kb = $image_size / 1000;
if( $first_image_time – $image_time < $max_image_time_difference) // Show image { echo "
“.date (“F d, Y g:i A T”, $image_time);
echo ” $image_size_kb kB”;
echo “
“;

if ( $image_size == 0)
echo ” $hours hours upload quota exceeded. Needs to be fixed.”;
}
else // Don’t show more images
{
if($delete) // Delete the rest of the image files if TRUE
unlink($image); //delete
}

} // Image display loop

[/insert_php]