MikeDXUNL Posted November 28, 2008 Share Posted November 28, 2008 i've searched php.net and google. but there have no been sufficient ways to order a directory list by filetime() help would be appreciated. thanks. Link to comment https://forums.phpfreaks.com/topic/134592-solved-ordering-by-filetime/ Share on other sites More sharing options...
rhodesa Posted November 28, 2008 Share Posted November 28, 2008 <?php $folder = realpath('path/to/folder'); $files = array(); $times = array(); foreach(scandir($folder) as $file){ if(is_file($folder.'/'.$file)){ $files[] = $file; $times[] = filemtime($folder.'/'.$file); } } array_multisort($times,$files); print_r($files); ?> Link to comment https://forums.phpfreaks.com/topic/134592-solved-ordering-by-filetime/#findComment-700792 Share on other sites More sharing options...
MikeDXUNL Posted November 28, 2008 Author Share Posted November 28, 2008 well, it works. but when i upload a file... say i have photo1.jpg photo2.jpg already uploaded... then i upload photo3.jpg i need it to be photo3.jpg, photo2.jpg, photo1.jpg in that order... when i run your script; it gives me photo1.jpg, photo2.jpg, photo3.jpg Link to comment https://forums.phpfreaks.com/topic/134592-solved-ordering-by-filetime/#findComment-700800 Share on other sites More sharing options...
kenrbnsn Posted November 28, 2008 Share Posted November 28, 2008 Try something like this: <?php <?php $mtim = array(); foreach (glob('*.php') as $file) { $mtim[filemtime($file)] = $file; } krsort($mtim); foreach($mtim as $file) echo $file . "<br>\n"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/134592-solved-ordering-by-filetime/#findComment-700803 Share on other sites More sharing options...
rhodesa Posted November 28, 2008 Share Posted November 28, 2008 <?php $folder = realpath('path/to/folder'); $files = array(); $times = array(); foreach(scandir($folder) as $file){ if(is_file($folder.'/'.$file)){ $files[] = $file; $times[] = filemtime($folder.'/'.$file); } } array_multisort($times,SORT_DESC,$files); //Added Descending Here print_r($files); ?> Link to comment https://forums.phpfreaks.com/topic/134592-solved-ordering-by-filetime/#findComment-701000 Share on other sites More sharing options...
MikeDXUNL Posted November 29, 2008 Author Share Posted November 29, 2008 works like a charm... thanks rhodesa Link to comment https://forums.phpfreaks.com/topic/134592-solved-ordering-by-filetime/#findComment-701897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.