The touch() function sets access and modification time of a file. It returns TRUE on success, or FALSE on failure.
Syntax
touch(filename, time, atime)
Parameters
filename − Set the name of the file.
time − Set the time. The default is the current system time.
atime − Set the access time. The default is the current system time.
Return
The touch() function returns TRUE on success, or FALSE on failure.
Example
<?php
$myfile = "new.txt";
// changing the modification time to current system time
if (touch($myfile)) {
echo ("The modification time of $myfile set to current time.");
} else {
echo ("The modification time of $myfile can’t be updated.");
}
?>Output
The modification time of new.txt set to current time.
Let us see another example.
Example
<?php
$myfile = "new.txt";
$set_time = time() - 28800;
// changing the modification time
if (touch($myfile, $set_time)) {
echo ("The modification time of $myfile updated to 8 hrs in the past.");
} else {
echo ("The modification time of $myfile can’t be updated.");
}
?>Output
The modification time of new.txt updated to 8 hrs in the past.