Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

Retrieving File Time Information

Most filesystems store the time that each file was last accessed and last modified, often referred to as "atime" for the last access time and "mtime" for the last modification time. These are accessible through the PHP functions fileatime() and filemtime(). These return a Unix timestamp for the time, which you then need to convert using a call to date(), like this:

    $contacts = "contacts.txt";
    $atime = fileatime($contacts);
    $mtime = filemtime($contacts);

    $atime_str = date("F jS Y H:i:s", $atime);
    $mtime_str = date("F jS Y H:i:s", $mtime);
    // eg June 8th 2005 16:04:15

    print "File last accessed: $atime_str\n";
    print "File last modified: $mtime_str\n";

Note that some people disable "atime" on their filesystem as a performance optimization, making this data potentially unreliable. In this situation, you will still get a date and time returned for the "atime"; it is just likely to be out of date.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page