Re: File Modification Date/Time
| From: | Marek Kilimajer | Date: | Sun, 05 Jan 2003 14:26:39 +0000 |
| Subject: | Re: File Modification Date/Time | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-130316@lists.php.net to get a copy of this message | ||
This should be right, $TimeDiff is in seconds.
Christopher J. Crane wrote:
Doyou know how to compare time. I would like to get the difference in time from now to when the file was last accessed. I was thinking something like this: <?PHP $DirToCheck = "tempdata/"; echo "$Now<br><br>\n"; $TimeNow = time(); if ($handle = opendir($DirToCheck)) { while (false !== ($file = readdir($handle))) { $FileTimeUnix = fileatime($DirToCheck . $file); $TimeDiff = $TimeNow - $FileTimeUnix;echo " $file - Last accessed: " . date("F d Y H:i:s.",fileatime($DirToCheck . $file)) . " - $TimeDiff<br>\n"; if($TimeDiff > 10000) { unlink($DirToCheck . $file); } $TimeDiff = 0;}closedir($handle); } ?> "Marek Kilimajer" <kilimajer@webglobe.sk> wrote in message news:3E15BAD1.1020104@webglobe.sk...you must prepend $DirToCheck to $file: filemtime($DirToCheck . $file) Christopher J. Crane wrote:ofI am trying to parse through a directory and get the modification datesWhatthe file. <?PHP $DirToCheck = "tempdata/"; if ($handle = opendir($DirToCheck)) { while (false !== ($file = readdir($handle))) {echo " $file - Last Modified: " . date("F d Y H:i:s.",filemtime($file)) . "<br>\n"; } closedir($handle); } ?> All the files are coming back with a date of December 31 1969 19:00:00.thanam I doing wrong? The next step is I want to check if the file is older30 minutes and if so, I want to delete it. How would I go about that?