Introduction
This article explains Accessed and Modified Times in PHP. You will see the last access or modified file of your directory. The ability to work out a file's last access and modification time plays a crucial role in several administrative tasks, particularly in network applications that involve network or CPU intensive update operations. PHP offers 3 functions for determining a file's access, creation, and last modification time.
Syntax
Int fileatime ( string $filename ); |
This function gets the last file access time. The filename is required to include the path of the file to get the access time. Let's get the last accessed time of the file with examples.
Example
<?php
$Accessed1 = 'C:/wamp/www/text.php';
$Accessed2 = 'C:/wamp/www/test.php';
$Accessed3 = 'C:/wamp/www/exa.php';
$Accessed4 = 'C:/wamp/www/functions.js';
$Accessed5 = 'C:/wamp/www/mins.gif';
printf("Last Accessed this file: %s", date("m-d-y g:i:sa", fileatime($Accessed1)));
echo "<br>";
printf("Last Accessed this file: %s", date("m-d-y g:i:sa", fileatime($Accessed2)));
echo "<br>";
printf("Last Accessed this file: %s", date("m-d-y g:i:sa", fileatime($Accessed3)));
echo "<br>";
printf("Last Accessed this file: %s", date("m-d-y g:i:sa", fileatime($Accessed4)));
echo "<br>";
printf("Last Accessed this file: %s", date("m-d-y g:i:sa", fileatime($Accessed5)));
?>
Output
Syntax
Int filectime ( string $filename ); |
This function gets the last change time of the file.
Example
<?php
$Changed1 = 'C:/wamp/www/text.php';
$Changed2 = 'C:/wamp/www/test.php';
$Changed3 = 'C:/wamp/www/exa.php';
$Changed4 = 'C:/wamp/www/functions.js';
$Changed5 = 'C:/wamp/www/mins.gif';
printf("Last Changed this file: %s", date("m-d-y g:i:sa", filectime($Changed1)));
echo "<br>";
printf("Last Changed this file: %s", date("m-d-y g:i:sa", filectime($Changed2)));
echo "<br>";
printf("Last Changed this file: %s", date("m-d-y g:i:sa", filectime($Changed3)));
echo "<br>";
printf("Last Changed this file: %s", date("m-d-y g:i:sa", filectime($Changed4)));
echo "<br>";
printf("Last Changed this file: %s", date("m-d-y g:i:sa", filectime($Changed5)));
?>
Output
Syntax
Int filemtime ( string $filename ); |
This function gets the last modified time of a file. The last modified time differs from the last changed time the last modified time refers to any
change within the file's inode information.
Example
<?php
$modified1 = 'C:/wamp/www/text.php';
$modified2 = 'C:/wamp/www/functions.js';
printf("Last modified this file: %s", date("m-d-y g:i:sa", filemtime($modified1)));
echo "<br>";
printf("Last modified this file: %s", date("m-d-y g:i:sa", filemtime($modified2)));
?>
Output