Wednesday, June 10, 2026
HomeLanguagesPHP | fileatime( ) Function

PHP | fileatime( ) Function

The fileatime() function in PHP is an inbuilt function which is used to return the last access time of a specified file. The fileatime() function returns the last access time of a file as a Unix Timestamp on success and False on failure.

The filename is passed as a parameter to the fileatime() function. The result of the fileatime() function is cached and a function called clearstatcache() is used to clear the cache.

Syntax:

fileatime($filename)

Parameters: The fileatime() function in PHP accepts only one parameter $filename. It specifies the file whose last access time you want to check.

Return Value: It returns the last access time of a file as a Unix Timestamp on success and False on failure.

Errors And Exception:

  1. The time resolution may differ from one file system to another.
  2. This function doesn’t works on some unix systems which have access time updates are disabled to increase performance.

Examples:

Input : echo fileatime("gfg.txt");
Output : 1525159574

Input : echo "Last accessed: ".date("F d Y H:i:s.", 
                              fileatime("gfg.txt"));
Output : Last accessed: May 1 2018 07:26:14.

Below programs illustrate the fileatime() function.

Program 1:




<?php
  
// checking last accessed time of a file 
echo fileatime("gfg.txt");
  
?>


Output:

1525159574

Program 2:




<?php
  
// checking last accessed time of a file 
echo fileatime("gfg.txt");
  
//checking last accessed time of a file
// and formatting the output of the date 
echo "Last accessed: ".date("F d Y H:i:s.", 
                     fileatime("gfg.txt"));
?>


Output:

1525159574
Last accessed: May 1 2018 07:26:14.

Reference:
http://php.net/manual/en/function.fileatime.php

RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7018 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS