19.2. Getting and Setting File Timestamps
$last_access = fileatime('larry.php'); $last_modification = filemtime('moe.php'); $last_change = filectime('curly.php');
touch('shemp.php'); // set modification time to now touch('joe.php',$timestamp); // set modification time to $timestamp
The fileatime( ) function returns the last time a file was opened for reading or writing. The filemtime( ) function returns the last time a file's contents were changed. The filectime( ) function returns the last time a file's contents or metadata (such as owner or permissions) were changed. Each function returns the time as an epoch timestamp.
A file's modification time can be updated with touch( ). Without a second argument, touch( ) sets the modification time to the current date and time. To set a file's modification time to a specific value, pass that value as an epoch timestamp to touch( ) as a second argument.
This code prints the time a page on your web site was last updated:
print "Last Modified: ".strftime('%c',filemtime($_SERVER['SCRIPT_FILENAME']));
19.2.4. See Also
Copyright © 2003 O'Reilly & Associates. All rights reserved.