PHP touch()函数
touch() 函数可以设置指定文件的访问和修改时间,成功返回 true,失败返回 false。
语法
bool touch ( string filename [, inttime = time() [, int $atime ]] )
此函数可以尝试将文件名在filename参数中命名的文件的访问时间和修改时间设置为给定值time。请注意,无论参数的数量如何,访问时间总是会被修改。
示例1
<?php
filename = "/PhpProject/sample.txt";
if(touch(filename)) {
echo filename . " modification time has been changed to present time";
} else {
echo "Sorry, could not change modification time of " .filename;
}
?>
输出
/PhpProject/sample.txt modification time has been changed to present time
示例2
<?php
time = time() - 3600;
if (!touch("/PhpProject/sample.txt",time)) {
echo "oops, something went wrong...";
} else {
echo "Touched file with success";
}
?>
输出
Touched file with success