Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

touch

Description

The touch of Filesystem for PHP sets access and modification time of file.

Syntax

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

Parameters

filename

The name of the file being touched.

mtime

The touch time. If mtime is null, the current system time() is used.

atime

If not null, the access time of the given filename is set to the value of atime. Otherwise, it is set to the value passed to the mtime parameter. If both are null, the current system time is used.

Return

Returns true on success or false on failure.

Examples

1 · filename

<?

$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 · mtime

<?

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

if(touch($filename, $mtime))
{
    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 · atime

<?

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

if(touch($filename, $mtime, $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

4 · return

<?

$filename = $_SERVER['DOCUMENT_ROOT'];

$return = touch($filename);

var_export($return);

?>
true
HomeMenu