touch
(PHP 4, PHP 5, PHP 7)
touch - 设置文件的访问和修改时间
描述
bool touch ( string $filename [, int $time = time() [, int $atime ]] )
尝试将filename
参数中指定的文件的访问和修改时间设置为中给出的值time
。请注意,无论参数的数量如何,访问时间总是会被修改。
如果该文件不存在,它将被创建。
参数
filename
被 touch 的文件的名称。
time
touch 时间。如果time
未提供,则使用当前的系统时间。
atime
如果存在,给定文件名的访问时间被设置为的值atime
。否则,它被设置为传递给time
参数的值。如果两者都不存在,则使用当前的系统时间。
返回值
成功时返回TRUE
或失败时返回FALSE
。
Changelog
版本 | 描述 |
---|---|
5.3.0 | 有可能在Windows下更改目录的修改时间。 |
示例
Example #1 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 #2 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';
}
?>
注意
注意:请注意,时间分辨率可能因文件系统而异。
警告
在PHP 5.3.0之前,无法在 Windows 下使用此功能更改目录的修改时间。
← tmpfile
umask →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com