-1

I have the following code:

public static function getLogFiles()
{
    $dir    = '../tmp/logs';
    $files = scandir($dir);

    foreach ($files as $filename){
        echo "$filename wurde zuletzt modifiziert:: " . date ("F d Y H:i:s.", filemtime($filename)) . "<br>";
    }

    die();
}

For debug I used

print_r($files);

and get an array with all files. But I only get the first two modifieddates:

 . wurde zuletzt modifiziert:: January 14 2013 09:06:05. 

.. wurde zuletzt modifiziert:: December 14 2012 10:46:34.


Warning (2): filemtime(): stat failed for Fleetster.log [APP\Lib\Log4All.php, line 134]

system.log wurde zuletzt modifiziert:: January 01 1970 01:00:00.

Warning (2): filemtime() [function.filemtime]: stat failed for debug.log [APP\Lib\Log4All.php, line 134]

debug.log wurde zuletzt modifiziert:: January 01 1970 01:00:00.

Warning (2): filemtime() [function.filemtime]: stat failed for error.log [APP\Lib\Log4All.php, line 134]

error.log wurde zuletzt modifiziert:: January 01 1970 01:00:00.

What is wrong?

Thank you and best regards

Binary
  • 133
  • 2
  • 8

1 Answers1

0

If you file is too big for stat() (it uses that function), you'll get this. The comments on the manual page say;

If PHP's integer type is only 32 bits on your system, filemtime() will fail on files over 2GB with the warning "stat failed". All stat()-related commands will exhibit the same behavior.

There might be different reasons for stat() to say this, depending on your situation.

Nanne
  • 64,065
  • 16
  • 119
  • 163
  • Thanks but the biggest file is 63KB big – Binary Jan 16 '13 at 13:30
  • ok, and how are the permissions of these failing files? You can't stat a file you don't have permissions for – Nanne Jan 16 '13 at 13:33
  • I'm not sure. I'm logged in as an admin on win8. It is possible to read the files in the array. Also I'm getting this information for "." and ".." whatever that is... Is this enough to make sure I have enough permissions? – Binary Jan 16 '13 at 13:34