Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

filemtime

Returns the time a file was last modified.

Syntax

filemtime(string $filename): int|false

Parameters

ParameterTypeDescription
$filenamestringThe 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

  • filesize — Returns the size of a file in bytes.
  • date — Formats a date and time.
  • touch — Creates an empty file or updates its modification time.

In the tutorial

  • Reading and writing files — Working with files in PHP — writing, reading, appending, reading line by line, checking existence and deleting.

Thanks for reading!

Donate to the site — we work hard for you.