(PHP 4, PHP 5)
touch — 设定文件的访问和修改时间
$filename
[, int $time
[, int $atime
]] )
尝试将由 filename
给出的文件的访问和修改时间设定为给出的时间。如果没有给出可选参数
time
,则使用当前系统时间。如果给出了第三个参数
atime
,则给定文件的访问时间会被设为
atime
。注意访问时间总是会被修改的,不论有几个参数。
如果文件不存在,则会被创建。成功时返回 TRUE
, 或者在失败时返回 FALSE
.
Example #1 touch() 例子
<?php
if (touch($FileName)) {
echo "$FileName modification time has been changed to present time";
} else {
echo "Sorry, could not change modification time of $FileName";
}
?>
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.
成功时返回 TRUE
, 或者在失败时返回 FALSE
.
版本 | 说明 |
---|---|
5.3.0 | It became possible to change the modification time of a directory under Windows. |
Example #2 touch() example
<?php
if (touch($filename)) {
echo $filename . ' modification time has been changed to present time';
} else {
echo 'Sorry, could not change modification time of ' . $filename;
}
?>
Example #3 touch() using the time
parameter
<?php
// This is the touch time, we'll set it to one hour in the past.
$time = time() - 3600;
// Touch the file
if (!touch('some_file.txt', $time)) {
echo 'Whoops, something went wrong...';
} else {
echo 'Touched file with success';
}
?>
Note:
注意:不同文件系统对时间的判断方法可能是不相同的。
Prior to PHP 5.3.0 it was not possible to change the modification time of a directory with this function under Windows.