Re: most latest file
| From: | Jason Barnett | Date: | Tue, 27 Apr 2004 03:18:26 +0000 |
| Subject: | Re: most latest file | ||
| References: | 1 2 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-23556@lists.php.net to get a copy of this message | ||
Harpreet wrote:
Actually I have a backups folder that gets once a day backups of the database automaticcaly. I want to be able to know the name fo the the latest file to do the restore. The name of the files have the time stamp and plus file has a time last mdified date attached to it. How can I know which file got restored last using php and also the file name. Thanks<?php $directory = 'path/to/backups/directory'; $handle = opendir($directory) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && fileatime($file) > $time) {
$time = fileatime($file);
$lastModifiedFile = $file;
}
}
closedir($handle);
echo $lastModifiedFile;
?>
http://www.php.net/readdir
http://www.php.net/manual/en/function.fileatime.php
or, to check file creation times:
http://www.php.net/manual/en/function.filectime.php