Back to Top

How to get File access and modification Time

How to get File access and modification Time

It is necessary to get the time when the file is accessed and modified. In the section, you learned how to access and modification Time in PHP.

Here I am going to cover one quick article about three file functions fileatime( ) , filemtime( ), and filectime( ) which returns the time of last access, modification, and metadata change of a file respectively.

What is fileatime()?

fileatime() function gives the access time of the file is updated when you open a file or when it is used for other operations.

What is filemtime()?

filemtime() function gives the modification time of the file when you change the contents or save the file.

What is filectime()?

filectime() function gives the time of file when change file attributes, such as file owner, permissions, or moved to another file system. It is also update and change the file modification time.

We can use one more file function touch() which sets the access and modification time of file.We can say touch() function returns file touch time.


Here, First parameter filename specifies the name of the file.second parameter is the modification time that will change. The time parameter is directly responsible for the prescribed time. The time parameter is optional so you can ignore it you want to set the current time.

Let’s have a look of touch function used as:

The second parameter in touch() function is optional and without the second parameter, touch() set current date and time of modification of a file.To set a modification time of file with the specific value, pass that value as a timestamp to touch( ) function as a second parameter.

Now Let’s get some basic idea about fileatime( ) , filemtime( ), and filectime( ) functions:

The fileatime( ) function returns the last time a file was opened for reading or writing.

The filemtime( ) function returns the last time the contents of files were changed.

The filectime( ) function returns the last time a contents or metadata like an owner or permissions of files were changed.

NOTE: Each function gives the time as an timestamp.

Above example will gives the actual last modification time of File.


Also Read:

Method Chaining in PHP
To Unzip file and move to destination in PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular Posts

How to use Ajax in WordPress

Posted on 4 years ago


Learn ElasticSearch in 10 Minutes

Posted on 2 years ago