0

I have this script. It works by taking all the pictures in a folder, and make a webpage of it. Oldest picture on top, and newer pictures down the page.

How can I revert the way the pictures are displayed? I want the newest on top.

<?php
$folder = 'ute/grabs/';
$filetype = '*.*';
$files = glob($folder.$filetype);
$count = count($files);
echo '<table>';
for ($i = 0; $i < $count; $i++) {
echo '<tr><td>';
echo '<a name="'.$i.'" href="#'.$i.'"><img src="'.$files[$i].'" /></a>';
echo substr($files[$i],strlen($folder),strpos($files[$i], '.')-strlen($folder));
echo '</td></tr>';
}
echo '</table>';
?>
Mahendra Gunawardena
  • 1,956
  • 5
  • 26
  • 45
Bergum
  • 77
  • 9

2 Answers2

0

Put this after glob.

usort($files, create_function('$b,$a', 'return filemtime($a) - filemtime($b);'));

See: glob() - sort by date

Note: I have changed the first argument of the "create_function" to reverse the order.

Community
  • 1
  • 1
Icarus3
  • 2,310
  • 14
  • 22
0

Thank you Icarus3 That worked great.

This was the final solution:

<?php
$folder = 'webcam/webcam/ute/grabs/';
$filetype = '*.jpg';
$files = glob($folder.$filetype);
usort($files, create_function('$b,$a', 'return filemtime($a) - filemtime($b);'));
$count = count($files);
echo '<table>';
for ($i = 0; $i < $count; $i++) {
echo '<tr><td>';
echo '<a name="'.$i.'" href="#'.$i.'"><img src="'.$files[$i].'" /></a><br>';
echo substr($files[$i],strlen($folder),strpos($files[$i], '.')-strlen($folder));
echo '</td></tr>';
}
echo '</table>'; 
?>
Bergum
  • 77
  • 9