English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Filesystem Reference Manual
The fileatime() function can return the last access time of the specified file. If successful, this function can return the last access time as a Unix timestamp, or return false if it fails.
int fileatime ( string $filename )
The result of this function is cached. We can use the clearstatcache() function to clear the cache.
The access time of the file can be changed every time a data block in the file is read. Some Unix systems may disable access time updates because updating access times can affect performance when applications regularly access a large number of files. Disabling access time updates can improve the performance of such programs.
Format and output the last access timestamp of the file
<?php echo fileatime("sample.txt"); echo "\n"; echo "Last accessed: ".date("F d Y H:i:s.",fileatime("sample.txt")); ?>
Output Result
1590217956 Last accessed: May 23 2020 09:12:36.
Firstly, check if the file exists, then view the last access timestamp of the file and format the output
<?php $filename = "/PhpProject/sample.txt"; if(file_exists($filename)) { echo "$filename Last accessed time: " . date("F d Y H:i:s.", fileatime($filename)); } ?>
Output Result
/PhpProject/sample.txt Last accessed time: May 23 2020 09:12:36.