PHP touch()函数

PHP touch()函数

touch() 函数可以设置指定文件的访问和修改时间,成功返回 true,失败返回 false。

语法

bool touch ( string filename [, inttime = time() [, int $atime ]] )
PHP

此函数可以尝试将文件名在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;
   }
?>
PHP

输出

/PhpProject/sample.txt modification time has been changed to present time
PHP

示例2

<?php
   time = time() - 3600;
   if (!touch("/PhpProject/sample.txt",time)) {
      echo "oops, something went wrong...";
   } else {
      echo "Touched file with success";
   }
?>
PHP

输出

Touched file with success
PHP

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册