首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

touch

(PHP 4, PHP 5, PHP 7)

touch - 设置文件的访问和修改时间

描述

代码语言:javascript
复制
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

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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 →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com