Reputation: 55
I was wondering if it where possible to see, with PHP, when the last time a folder was accessed. I was thinking about using 'touch()' in php but that's more for a file, isn't it?
Thanks in advance!
Upvotes: 4
Views: 485
Reputation: 13476
As far as I know this information is only stored about files (According to others this is wrong and it is for directories - see Dinesh's answer). However you can iterate over each file in a directory and discover the most recently accessed file in the directory (Not exactly what you want but possibly as close as you will get). Using the DirectoryIterator
:
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
$accessed = 0;
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile()) {
if ($fileinfo->getATime() > $accessed) {
$accessed = $fileinfo->getAtime();
}
}
}
print($accessed);
?>
http://php.net/manual/en/directoryiterator.getatime.php
Upvotes: 4
Reputation: 63442
You can use fileatime()
, which works for both files and directories:
fileatime('dir');
Upvotes: 4
Reputation: 1967
I would open the folder and loop through the files (you can use glob()
for that) and grab the latest edited time with filemtime()
.
http://php.net/manual/en/function.filemtime.php
http://www.php.net/manual/en/function.glob.php
i can post a small example if you still need help
Upvotes: 0