Syntax:int DirectoryIterator::getMTime (void)
Parameters:This function takes no parameters.
Return Value:This function returns the last modified time of the file in Unix timestamp format.The following programs illustrate the DirectoryIterator::getMTime() function in PHP:
Program 1:
// Create an Iterator directory
$directory
=
new
DirectoryIterator (dirname (
__ FILE__
));
// Loop while the directory is valid
while
(
$directory
-> valid()) {
// Check this directory or not
if
(
$directory
-> isDir()) {
$file
=
$directory
-> current();
// Display the file name and last modified time
echo
$file
-> getFilename().
"| MTime:"
.
$directory
-> getMTime().
"
"
;
}
// Move to next catalog item
$directory
-> next();
}
?>
Output:. | MTime: 1574616421 .. | MTime: 1574540515 dashboard | MTime: 1574350724 img | MTime: 1574350724 webalizer | MTime: 1574350718 xampp | MTime: 1574350724
Program 2:
// Create an Iterator directory
$directory
=
new
DirectoryIterator (dirname (
__ FILE__
));
// Loop for each directory item
foreach
(
$directory
as
$dir
) {
// Save the current directory item
$file
=
$directory
-> current();
// Show key, file name and last modified time
echo
$dir
-> key().
"= >"
.
$file
-> getFilename().
"| MTime:"
.
$dir
-> getMTime().
"
"
;
}
?>
Output:0 = > ... | MTime: 1574616421 1 = > .. | MTime: 1574540515 2 = > applications.html | MTime: 1566914572 3 = > bitnami.css | MTime: 1566914572 4 = > dashboard | MTime: 1574350724 5 = > favicon.ico | MTime: 1437060752 6 = > engineer.PNG | MTime: 1573806007 7 = > gfg.php | MTime: 1574653649 8 = > img | MTime: 1574350724 9 = > index.php | MTime: 1437060752 10 = > webalizer | MTime: 1574350718 11 = > xampp | MTime: 1574350724
Note . The output of this function depends on the contents of the server folder.Link: https : //www.php.net/manual/en/directoryiterator.getmtime.php