filemtime()
filemtime() — Gets file modification time.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
This function returns the time when the data blocks of a file were being written to, that is, the time when the content of the file was changed.
Signature
filemtime(string $filename): int|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $filename | string | Path to the file. |
Return value
Returns the time the file was last modified, or false on failure. The time is returned as a Unix timestamp, which is suitable for the date() function.
Example
A runnable snippet:
// outputs e.g. somefile.txt was last modified: December 29 2002 22:16:23. $filename = 'somefile.txt'; if (file_exists($filename)) { echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename)); }
See also
filectime(), stat(), touch(), getlastmod()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page filemtime() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.