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. Quote Link to comment 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); ?> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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); ?> Quote Link to comment Share on other sites More sharing options...
MikeDXUNL Posted November 29, 2008 Author Share Posted November 29, 2008 works like a charm... thanks rhodesa Quote Link to comment 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.