mauibrew : I gave the same situation.
Folders are like
…./wp-content/uploads/webcam/
In this folder I have the local IP of the DVR device = 192.168.1.8
In that one, for each day
/2018-11-16
/2018-11-17
In these date named folder, the iage are uploaded with names like
DVR_ch7_20181117001022_T.jpg
My typical image file path is :
/path/to/where/are/your/files/wp-content/uploads/webcam/192.168.1.8/2018-11-17/DVR_ch7_20181117001022_T.jpg
As said, the /2018-11-17/ part changes every day.
I changed the get_last_filename function like this :
function get_last_filename($subdir) {
$upload_dir = wp_upload_dir();
$webcam_dir = $upload_dir['basedir'] . '/' . WEBCAM_DIR . '/' ;
if ($subdir && preg_match('/[a-z0-9]/i', $subdir)) {
$webcam_dir .= $subdir . '/';
}
$files = getDirContents($webcam_dir);
// Return the (relative path to the) file name - without the first '/'
return deleteFirstChar(str_replace(realpath($webcam_dir), '',end($files)));
};
My function getDirContents is like this
function getDirContents($dir, &$results = array()){
$files = scandir( $dir );
foreach($files as $key => $value){
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
if(!is_dir($path)) {
if (filesize($path) > 0)
$results[] = $path;
} else if($value != "." && $value != "..") {
getDirContents($path, $results);
}
}
return $results;
}
as you already might have noticed, these directories will be filled up.
I advise you to use a cron-like tool to clean them up.
A simple shell script exampe :
#!/bin/sh
find /path/to/where/are/your/files/wp-content/uploads/webcam/192.168.1.8 -depth -mindepth 1 -mmin +60 -uid 1001 -exec rm -rdf {} \;
which runs every day and removes all files and folders older then 60 minutes.