File list, order and limit by date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

File list, order and limit by date

Post 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.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: File list, order and limit by date

Post by McInfo »

See
  • fileatime()
  • filectime()
  • filemtime()
  • stat()
PHP Manual: Filesystem Functions
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: File list, order and limit by date

Post by JKM »

Thanks, but I'm not sure how this would help me with only showing the 100 latest files.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: File list, order and limit by date

Post 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().
Post Reply