touch

Sets access and modification time of file

Syntax

touch ( string $filename [, int $time = time() [, int $atime ]] ) : bool

Parameters

filename

The name of the file being touched.

time

The touch time. If time is not supplied, the current system time is used.

atime

If present, the access time of the given filename is set to the value of atime. Otherwise, it is set to the value passed to the time parameter. If neither are present, the current system time is used.

Return

Returns TRUE on success or FALSE on failure.

Examples

1

<?

$filename = $_SERVER['DOCUMENT_ROOT'];

if (touch($filename)) {
    echo 'access time and modification time set to current time';
} else {
    echo 'touch() failed';
}

?>
access time and modification time set to current time

2

<?

$filename = $_SERVER['DOCUMENT_ROOT'];
$time = time() - 3600;

if (touch($filename, $time)) {
    echo 'access time and modification time set to one hour in the past';
} else {
    echo 'touch() failed';
}

?>
access time and modification time set to one hour in the past

3

<?

$filename = $_SERVER['DOCUMENT_ROOT'];
$time = time() - 3600;
$atime = time() - 7200;

if (touch($filename, $time, $atime)) {
    echo 'access time set to two hours in the past and modification time set to one hour in the past';
} else {
    echo 'touch() failed';
}

?>
access time set to two hours in the past and modification time set to one hour in the past
HomeMenu