Camera to Facebook

[insert_php]
require_once __DIR__ . ‘/../facebook-php-sdk-v4-5.0.0/src/Facebook/autoload.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
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
echo “\nCamera Images“;
// Time Zone http://php.net/manual/en/timezones.php
date_default_timezone_set(‘Canada/Eastern’);

// Number of images to display
$number_of_images = 1; // Camera 1
$number_of_images2 = 0; // Camera 2

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

// Skip images
// The Escam takes two pictures on motion detection
// 1 don’t skip (Foscam does not need skipping)
// 2 , 3 , 4 skip the next n-1 images
$skip_image = 1; //this value must not be zero

// 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”;

// Ftp directory(s) where camera puts images
// paul/ipcamera/2015/12/31/pictures
// paul/ipcamera/2016/1/1/pictures
// would be paul/ipcamera/*/*/*/pictures
// with this pattern all the directories under paul/ipcamera would be included
// remember to routinely manually delete folders when no longer required
// Foscam public_html/lmac.ca/camera/FI9803P_00626E586324/snap
// Escam public_html/lmac.ca/camera2/20160513/IMG001
$image_locations = “lmac.ca/camera/*/*/*”;
$image_locations2 = “lmac.ca/camera2/*/*/*”;

// 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
$search = $image_locations.$file_names;
$search2 = $image_locations2.$file_names;

// Get image files from locations in $search
$images = glob($search, GLOB_BRACE);
$images2 = glob($search2, GLOB_BRACE);

//reverse sort, sort descending, newest images first based on file name
rsort($images);
rsort($images2);

// Setting an image counter
$image_count = 0;
$image_count2 = 0;

// Setting a file size counter
$total_file_size = 0 ;
$total_file_size2 = 0 ;

// Setting a reference time
$first_image_time = filemtime($images[0]);
$first_image_time2 = filemtime($images2[0]);

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

// CAMERA 1
// Image display loop
// writes out the HTML code required to show the images
foreach($images as $image)
{

if($number_of_images > 0) // Show image
{
$total_file_size += filesize($image);
$image_count++;
//echo “$image”;
echo “
“.date (“F d, Y g:i a T”, filemtime($image));
echo “
“;
$number_of_images–; // Image shown, reduce counter
}
else // Don’t show more images, keep some, delete the rest
{
$image_time = filemtime($image);
if( $first_image_time – $image_time < $max_image_time_difference) // Keep image { $total_file_size += filesize($image); $image_count++; } else // Delete images { if($delete) // Delete the rest of the image files if TRUE unlink($image); //delete } } } // Image display loop CAMERA 1 // CAMERA 2 // Image display loop // writes out the HTML code required to show the images foreach($images2 as $image) { if($number_of_images2 > 0) // Show image
{
$total_file_size2 += filesize($image);
$image_count2++;
//echo “$image”;
echo “
“.date (“F d, Y g:i a T”, filemtime($image));
echo “
“;
$number_of_images2–; // Image shown, reduce counter
}
else // Don’t show more images, keep some, delete the rest
{
$image_time = filemtime($image);
if( $first_image_time – $image_time < $max_image_time_difference) // Keep image { $total_file_size2 += filesize($image); $image_count2++; } else // Delete images { if($delete) // Delete the rest of the image files if TRUE unlink($image); //delete } } } // Image display loop CAMERA 2 if ($image_count > 0)
{
$total_file_size = round( ($total_file_size / 1024 / 1024), 1 ) ; // Convert to MB and round.
$average_file_size = round( ($total_file_size / $image_count * 1024 ), 1 ) ; // Convert to KB/file and round
echo “
Camera 1“;
echo “
$image_count pictures in archives, “;
echo $total_file_size.” Megabytes.”;
echo “
Average file size “.$average_file_size.” Kilobytes” ;
}
if ($image_count2 > 0)
{
$total_file_size2 = round( ($total_file_size2 / 1024 / 1024), 1 ) ; // Convert to MB and round.
$average_file_size2 = round( ($total_file_size2 / $image_count2 * 1024 ), 1 ) ; // Convert to KB/file and round
echo “
Camera 2“;
echo “
$image_count2 pictures in archives, “;
echo $total_file_size2.” Megabytes.”;
echo “
Average file size “.$average_file_size2.” Kilobytes” ;
}

[/insert_php]