pneudralics Posted August 21, 2009 Share Posted August 21, 2009 I'm using this script, but am failing trying to sort it by the newest uploaded images first. http://www.ricocheting.com/scripts/gallery.html The below does it alphabetically. function GetFileList($dirname="."){ global $config; $list = array(); if ($handle = opendir($dirname)) { while (false !== ($file = readdir($handle))) { //this matches what type of files to get. jpeg, jpg, gif, png (ignoring case) if (preg_match("/\.(jpe?g|gif|png)$/i",$file)) { $list[] = $file; } } closedir($handle); } sort($list); return $list; }#-#GetFileList() Quote Link to comment https://forums.phpfreaks.com/topic/171312-how-can-i-sort-images-in-a-directory-by-the-date-they-were-uploaded/ Share on other sites More sharing options...
ignace Posted August 21, 2009 Share Posted August 21, 2009 Use filectime() function getFileList($directory) { $files = array(); if (!is_dir($directory) || !is_readable($directory)) return $files; if ($handle = opendir($directory)) { while (false !== ($file = readdir($handle)) { if (preg_match('/\.(jpe?g|gif|png)$/i', $file)) { $fullpath = implode(DIRECTORY_SEPARATOR, array($directory, $file)); $files[] = $fullpath; } } usort($files, create_function('$f1, $f2', '$f1ct = filectime($f1); $f2ct = filectime($f2); if ($f1ct === $f2ct) { return 0; } return $f1ct < $f2ct ? -1 : 1;')); } return $files; } Not sure this will work just wrote it out of the top of my head. Quote Link to comment https://forums.phpfreaks.com/topic/171312-how-can-i-sort-images-in-a-directory-by-the-date-they-were-uploaded/#findComment-903503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.