filemtime
Returns the time a file was last modified.
Syntax
filemtime(string $filename): int|falseParameters
| Parameter | Type | Description |
|---|---|---|
| $filename | string | The path to the file. |
Return value
int|falseA timestamp, or `false`.
Examples
The file was just modified:
<?php
$file = sys_get_temp_dir() . '/ref-mtime.txt';
file_put_contents($file, 'x');
var_dump(time() - filemtime($file) < 5);Output:
bool(true)Notes
The modification time is appended to style and script addresses — style.css?v=1712345678 — so that the browser loads the new version.
See also
In the tutorial
- Reading and writing files — Working with files in PHP — writing, reading, appending, reading line by line, checking existence and deleting.