当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP touch()用法及代码示例



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

用法

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

此函数可以尝试将 filename 参数中命名的文件的访问和修改时间设置为给定的时间值。请注意,无论参数数量如何,访问时间总是会被修改。

示例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

相关用法


注:本文由纯净天空筛选整理自 PHP - Function touch()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。