Page 1 of 1

File list, order and limit by date

Posted: Fri Jun 18, 2010 5:24 pm
by JKM
Hi there,

I'm using opendir() and readdir() to make a file list, but I was wondering if it's possible to only show the 100 (or something) latest files.

Thanks.

Re: File list, order and limit by date

Posted: Fri Jun 18, 2010 6:02 pm
by McInfo
See
  • fileatime()
  • filectime()
  • filemtime()
  • stat()
PHP Manual: Filesystem Functions

Re: File list, order and limit by date

Posted: Sat Jun 19, 2010 2:20 pm
by JKM
Thanks, but I'm not sure how this would help me with only showing the 100 latest files.

Re: File list, order and limit by date

Posted: Sat Jun 19, 2010 8:31 pm
by McInfo
You will have to loop through all of the files and call one of the functions I listed to get a time for each file. Store the file names and times in two arrays or one two-dimensonal array. Sort the files based on the times using array_multisort() or usort(). (Need a hint?) To limit the number of files, use a loop to copy at most 100 elements to a new array or use array_slice().