У меня есть веб-камера, которая загружает изображения каждые 30 секунд c в папки на моем ftp-сервере. Изображения помещаются в подпапки (например, 2020 -> 06 -> 19).
Я хочу перечислить их с помощью php в слайдере галереи - где самое новое изображение помещается первым.
Я нашел этот код в Интернете, к сожалению, мой опыт работы с php не очень хорош. Код работает для меня, но мне просто нужна опция для сортировки изображений по дате (сначала самые новые изображения).
Может ли кто-нибудь мне помочь с этим?
спасибо !!
<?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 );
?>