Take a look to piece of code used in a project. and you can adjust this according to your requirement.
$folder = 'images/';
$filetype = '*.*';
$files = glob($folder.$filetype);
$count = count($files);
$sortedArray = array();
for ($i = 0; $i < $count; $i++) {
$sortedArray[date ('YmdHis', filemtime($files[$i]))] = $files[$i];
}
ksort($sortedArray);
echo '<table>';
foreach (array_slice($sortedArray), 0, 10) as &$filename) {
#echo '<br>' . $filename;
echo '<tr><td>';
echo '<a name="'.$filename.'" href="#'.$filename.'"><img src="'.$filename.'" /></a>';
echo substr($filename,strlen($folder),strpos($filename, '.')-strlen($folder));
echo '</td></tr>';
}
echo '</table>';
and if you want to have the newest images at the top instead of at the bottom, then change this line:
ksort($sortedArray);
to this:
krsort($sortedArray);
Update apply the limit:
To apply the limit, you can simply apply counter or array slice function under final foreach and get top of your images.