Section 13.6. Retrieving File Time Information


13.6. 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.



PHP in a Nutshell
Ubuntu Unleashed
ISBN: 596100671
EAN: 2147483647
Year: 2003
Pages: 249

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net