Posted By

romanos on 06/13/08


Tagged

date folder directory


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

JimiJay
carlosabargues
dsntos
silentbob84


List directory contents by date


 / Published in: PHP
 

URL: http://www.jonasjohn.de/snippets/php/listdir-by-date.htm

Loads the contens of a dir an sorts them by the date of creation.

  1. function listdir_by_date($path){
  2. $dir = opendir($path);
  3. $list = array();
  4. while($file = readdir($dir)){
  5. if ($file != '.' and $file != '..'){
  6. // add the filename, to be sure not to
  7. // overwrite a array key
  8. $ctime = filectime($data_path . $file) . ',' . $file;
  9. $list[$ctime] = $file;
  10. }
  11. }
  12. closedir($dir);
  13. krsort($list);
  14. return $list;
  15. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: bdario on June 28, 2011

I noticed a problem on line 8. You wrote: $ctime = filectime($data_path . $file) . ',' . $file;

but I guess it have to be: $ctime = filectime($path . $file) . ',' . $file;

Am I wrong? Thank you for sharing

You need to login to post a comment.