The Way to Programming
The Way to Programming
I have the following script to show images from a directory and make thumbs , but I would like to know how to sort the images from newest to oldest and how to implement it in this script.
'; $count = 0; $skip = $page * $per_page; if ( $skip != 0 ) $has_previous = true; while ( $count < $skip && ($file = readdir($handle)) !== false ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) $count++; } $count = 0; while ( $count < $per_page && ($file = readdir($handle)) !== false ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) { // make the thumbs directory if it doesn't already exist if ( ! is_dir('thumbs') ) { mkdir('thumbs'); } // make a thumbnail if it doesn't already exist if ( ! file_exists('thumbs/'.$file) ) { makeThumb( $file, $type ); } // create a link to $file, add the thumbnail echo '
cobusbo is offline View user’s profile Send private message
Assuming the above code is yours, then have a look at :
http://php.net/manual/en/function.filemtime.php
simply read the file modification time of the picture into an array alongside with the picture (file) name, run a asort over the array and there you go, then loop through the array and output it.
the correct place is here :
if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) { // make the thumbs directory if it doesn't already exist if ( ! is_dir('thumbs') ) { mkdir('thumbs'); } // make a thumbnail if it doesn't already exist if ( ! file_exists('thumbs/'.$file) ) { makeThumb( $file, $type ); } // create a link to $file, add the thumbnail echo '
Sign in to your account