The scandir command returns an array with a list of files in the directory. The second parameter indicates the sort order (default is ascending, 1 for descent).
<?php
$dir = '/tmp';
$files = scandir($dir, 1);
$last_file = $files[0];
print($last_file);
?>
source
share