tags:

views:

29

answers:

2

Can we get the Directory's Modified time and size i.e. stats in php? How?

+1  A: 

Yes. You can make use of stat function

$stat = stat('\path\to\directory');
echo 'Modification time: ' . $stat['mtime']; // will show unix time stamp.
echo 'Size: ' . $stat['size']; // in bytes.
codaddict
+2  A: 

You can get the modified time with filemtime or SplFileInfo::getMTime.

As for getting the size of the directory, do you mean the file size of all of the contents within it (might sound like a silly question, size is ambiguous)?

If you are wanting just the recorded 'filesize' of the directory then filesize or SplFileInfo::getSize should suffice.

$dir = new SplFileInfo('path/to/dir');
printf(
    "Directory modified time is %s and size is %d bytes.", 
    date('d/m/Y H:i:s', $dir->getMTime()),
    $dir->getSize()
);
salathe