7.1 Working with Timestamps


You need to get the date that a file was last modified or set the modification date of a file.

Technique

To get the timestamp of a file, use the file*time() functions:

 print "$fn was last accessed on: " . fileatime ($fn); print "$fn was last changed on: " . filectime ($fn); print "$fn was last modified on: " . filemtime ($fn); 

To change the modification time of a file, use the touch() function:

 <?php if (touch ($fn, $date)) {     print "Timestamp changed..."; } else {     print "Modification Failed"; } ?> 

Comments

On a UNIX system (where the stat functions will work), there are three different times associated with a particular file: the atime , the ctime , and the mtime . The atime (get with fileatime() ) is the last time that the file was accessed. This is changed when the file is opened for read or write access. The ctime value is the time when the file's inode was last changed. Finally, the mtime is the time at which the file was last modified.

In PHP, the touch() function is the only way to change a file's timestamp information, and the only thing that touch() changes is the modification time of a file. Therefore, unless you go outside of PHP through exec () or system() , you cannot change anything but the mtime of a file.



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

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