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


PHP stat()用法及代碼示例


stat() 函數可以返回有關文件的信息。

用法

array stat ( string $filename )

該函數可以收集以文件名命名的文件的統計信息。如果文件名是符號鏈接,則統計信息來自文件本身,而不是符號鏈接。 lstat() 函數與 stat() 函數相同,隻是它可以基於符號鏈接狀態。

示例1

<?php
   $stat = stat("/PhpProject/sample.txt");  // Get file stat 

   echo "Acces time:" .$stat["atime"];    // Print file access time, this is the same as calling fileatime()  
   echo "\nModification time:" .$stat["mtime"];  //Print file modification time, this is the same as calling filemtime()
   echo "\nDevice number:" .$stat["dev"];  //  Print the device number
?>

輸出

Acces time:1590217956
Modification time:1591617832
Device number:1245376677

示例2

<?php
   $stat = stat("/PhpProject/sample.txt");
   
   if(!$stat) {
      echo "stat() call failed...";
   } else {
      $atime = $stat["atime"] + 604800;

   if(!touch("/PhpProject1/sampl2.txt", time(), $atime)) {
      echo "failed to touch file...";
   } else {
      echo "touch() returned success...";
   }
?>

輸出

touch() returned success...

相關用法


注:本文由純淨天空篩選整理自 PHP - Function stat()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。