當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。