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

5 COMMENTS

Most Popular

Dominic
32712 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7085 POSTS0 COMMENTS
Nicole Veronica
12225 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12308 POSTS0 COMMENTS
Shaida Kate Naidoo
7202 POSTS0 COMMENTS
Ted Musemwa
7467 POSTS0 COMMENTS
Thapelo Manthata
7187 POSTS0 COMMENTS
Umr Jansen
7171 POSTS0 COMMENTS