For me, using filemtime worked fine.
Example
<?php $path_to_file = '/tmp/'; echo filemtime($path_to_file);
Even if it is called the "mtime file", it also works for directories.
Caveat / gotcha
Make sure the file or directory that you are checking exists, otherwise you will get something like:
filemtime (): stat failed for / asdfasdfasdf in test.php on line 3
Possible fixes include something βcorrectβ:
$path = '/tmp/'; $mtime = file_exists($path)?filemtime($path):'';
And something less verbose but hacked using the error suppression operator ( @ ):
$path = '/tmp/'; $mtime = @filemtime($path);
filemtime ()
int filemtime (string $ filename )
This function returns the time when the data blocks of the file were written, that is, the time when the contents of the file were changed.
source share