In this article, you will learn how to set the access and update time of a file in PHP. The touch() function in PHP sets the access and modification time of the specified file. The file is created if not exist.
what is the syntax of the TOUCH function in php?
touch(filename, time, atime)
Parameter | Description |
---|---|
filename | Required. Specifies the file to touch |
time | Optional. Sets the touch time. The current system time is set by default |
atime | Optional. Sets the access time. Default is the current system time if no parameters are set, or the same as the time parameter if that parameter is set |
examples of the TOUCH function
Example 1. In this example, we set the access and modification time of the specified file.
<?php
filename = "test.txt";
if (touch($filename)) {
echo $filename . " modification time has been changed to present time";
} else {
echo "Sorry, could not change modification time of " . $filename;
}
?>