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!
You can use fileatime()
, which works for both files and directories:
fileatime('dir');
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With