php get meta data of file last time file was modified

Viewed 145

I want to get the meta data of a php file so I can see the last time the file was modified.

I have tried the following but not getting any data back

$file = fopen("index.php", 'r');
$meta = stream_get_meta_data($file);
print_r($meta);
fclose($file);

I get the following result

Array ( [timed_out] => [blocked] => 1 [eof] => [wrapper_type] => plainfile [stream_type] => STDIO [mode] => r [unread_bytes] => 0 [seekable] => 1 [uri] => index.php )
1 Answers

Stream metadata is not the same as the file metadata, since not all streams are connected to files.

Use fstat() to get the metadata of the file.

$meta = fstat($file);
echo date('Y-m-d H:i:s', $meta['mtime']);
Related