(PHP 4, PHP 5, PHP 7, PHP 8)
stat — 給出文件的信息
$filename): array
   獲取由 filename 指定的文件的統(tǒng)計(jì)信息。如果
   filename
   是符號(hào)連接,則統(tǒng)計(jì)信息是關(guān)于被連接文件本身的,而不是符號(hào)連接。
  
lstat() 和 stat() 相同,只除了它會(huì)返回符號(hào)連接的狀態(tài)。
filename文件的路徑。
| 數(shù)字下標(biāo) | 關(guān)聯(lián)鍵名(自 PHP 4.0.6) | 說明 | 
|---|---|---|
| 0 | dev | device number - 設(shè)備名 | 
| 1 | ino | inode number - inode 號(hào)碼 | 
| 2 | mode | inode protection mode - inode 保護(hù)模式 | 
| 3 | nlink | number of links - 被連接數(shù)目 | 
| 4 | uid | userid of owner - 所有者的用戶 id | 
| 5 | gid | groupid of owner- 所有者的組 id | 
| 6 | rdev | device type, if inode device * - 設(shè)備類型,如果是 inode 設(shè)備的話 | 
| 7 | size | size in bytes - 文件大小的字節(jié)數(shù) | 
| 8 | atime | time of last access (unix timestamp) - 上次訪問時(shí)間(Unix 時(shí)間戳) | 
| 9 | mtime | time of last modification (unix timestamp) - 上次修改時(shí)間(Unix 時(shí)間戳) | 
| 10 | ctime | time of last change (unix timestamp) - 上次改變時(shí)間(Unix 時(shí)間戳) | 
| 11 | blksize | blocksize of filesystem IO * - 文件系統(tǒng) IO 的塊大小 | 
| 12 | blocks | number of blocks allocated - 所占據(jù)塊的數(shù)目 | 
* - 僅在支持 st_blksize 類型的系統(tǒng)下有效。其它系統(tǒng)(如 Windows)返回 -1。
   如果出錯(cuò),stat() 返回 false。
  
注意: 因?yàn)?PHP 的整數(shù)類型是有符號(hào)整型而且很多平臺(tái)使用 32 位整型,對(duì) 2GB 以上的文件,一些文件系統(tǒng)函數(shù)可能返回?zé)o法預(yù)期的結(jié)果。
   錯(cuò)誤時(shí)會(huì)產(chǎn)生 E_WARNING 級(jí)別的錯(cuò)誤。
  
| 版本 | 說明 | 
|---|---|
| 4.0.6 | 返回一個(gè)數(shù)組包含有文件的統(tǒng)計(jì)信息,該數(shù)組具有以下列出的單元,數(shù)組下標(biāo)從零開始。除了數(shù)字索引之外自還可以通過關(guān)聯(lián)索引來訪問。 | 
示例 #1 stat() 例子
<?php
/* Get file stat */
$stat = stat('C:\php\php.exe');
/*
 * Print file access time, this is the same 
 * as calling fileatime()
 */
echo 'Access time: ' . $stat['atime'];
/*
 * Print file modification time, this is the 
 * same as calling filemtime()
 */
echo 'Modification time: ' . $stat['mtime'];
/* Print the device number */
echo 'Device number: ' . $stat['dev'];
?>
示例 #2 Using stat() information together with touch()
<?php
/* Get file stat */
$stat = stat('C:\php\php.exe');
/* Did we failed to get stat information? */
if (!$stat) {
    echo 'stat() call failed...';
} else {
    /*
     * We want the access time to be 1 week 
     * after the current access time.
     */
    $atime = $stat['atime'] + 604800;
    /* Touch the file */
    if (!touch('some_file.txt', time(), $atime)) {
        echo 'Failed to touch file...';
    } else {
        echo 'touch() returned success...';
    }
}
?>
注意:
注意:不同文件系統(tǒng)對(duì)時(shí)間的判斷方法可能是不相同的。
注意: 此函數(shù)的結(jié)果會(huì)被緩存。參見 clearstatcache() 以獲得更多細(xì)節(jié)。
自 PHP 5.0.0 起, 此函數(shù)也用于某些 URL 包裝器。請(qǐng)參見 支持的協(xié)議和封裝協(xié)議以獲得支持 stat() 系列函數(shù)功能的包裝器列表。