I do have a webcam, which uploads images every 30sec into folders on my ftp Server. The images are placed into subfolders (ex. 2020 -> 06 -> 19).
I want to list them with php into a gallery slider - where the newest image is placed first.
I found this code online, unfortunately, my experience in php isn't really good. The code works for me, but i just need an option for it to sort the images date-wise (newest images first).
Could anybody help me with that?
thank you!!
<?php
// file name: list_pics.php
global $startDir;
/**
* List Directories function, which transverses sub-folders
* listing out the image files that exists within it.
*/
function listDir( $path ) {
global $startDir;
$handle = opendir( $path );
while (false !== ($file = readdir($handle))) {
if( substr( $file, 0, 1 ) != '.' ) {
if( is_dir( $path.'/'.$file ) ) {
listDir( $path.'/'.$file );
}
else {
if( @getimagesize( $path.'/'.$file ) ) {
/*
// Uncomment if using with the below "pic.php" script to
// encode the filename and protect from direct linking.
$url = 'http://domain.tld/images/pic.php?pic='
.urlencode( str_rot13( substr( $path, strlen( $startDir )+1 ).'/'.$file ) );
*/
$url='http://domain.tld/images/'.
substr( $path, strlen( $startDir )+1 ).'/'.$file;
// You can customize the output to use img tag instead.
echo "<a href='".$url."'>".$url."</a><br>";
}
}
}
}
closedir( $handle );
} // End listDir function
$startDir = '.';
listDir( $startDir );
?>