Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

touch

Creates an empty file or updates its modification time.

Syntax

touch(string $filename, ?int $mtime = null, ?int $atime = null): bool

Parameters

ParameterTypeDescription
$filenamestringThe path to the file.
$mtime?intOptional. The new modification time.
$atime?intOptional. The new access time.

Return value

bool`true` on success.

Examples

Creating an empty file:

<?php
 
$file = sys_get_temp_dir() . '/ref-touch.lock';
touch($file);
 
var_dump(file_exists($file), filesize($file));

Output:

bool(true)
int(0)

Notes

The contents of an existing file are untouched — only the time is updated.

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.

Thanks for reading!

Donate to the site — we work hard for you.