Readdir Order

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kkbbzzaa
    Member
    • Jul 2004
    • 38

    #1

    Readdir Order

    I made this PHP script using a lot the function readdir(). I’m not happy with the order in which the files are displayed. I was trying to find out the logic of this order and found out at www.php.net that “The filenames are returned in the order in which they are stored by the filesystem.”

    I was wondering if there is any way to change this for the filesystem to display the folders by last modified.

    Thanks for your help.

    Mateo
    oxoia.com
  • waltonics
    Junior Member
    • Nov 2004
    • 28

    #2
    You need to use readdir() to get a list of files into an array or something, then, and Ive never used this function... but you would then sort that array by checking the file modified dates using filemtime()

    from the php manual:

    filemtime
    Gets file modification time (PHP 3, PHP 4 )
    int filemtime ( string filename )

    Returns the time the file was last modified, or FALSE in case of an error. The time is returned as a Unix timestamp.

    The results of this function are cached. See clearstatcache() for more details.

    This function will not work on remote files; the file to be examined must be accessible via the server's filesystem.

    Note: This function returns the time when the data blocks of a file were being written to, that is, the time when the content of the file was changed. Use date() on the result of this function to get a printable modification date for use in page footers.

    See also filectime() and touch().

    Comment

    Working...