(PHP 4, PHP 5)
stat — 給出文件的信息
說明
array stat ( string$filename
)
獲取由 filename
指定的文件的統計信息。如果
filename
是符號連接,則統計信息是關于被連接文件本身的,而不是符號連接。
lstat() 和 stat() 相同,只除了它會返回符號連接的狀態。
參數
filename
文件的路徑。
返回值
stat() 和 fstat() 返回格式 數字下標 關聯鍵名(自 PHP 4.0.6) 說明 0 dev device number - 設備名 1 ino inode number - inode 號碼 2 mode inode protection mode - inode 保護模式 3 nlink number of links - 被連接數目 4 uid userid of owner - 所有者的用戶 id 5 gid groupid of owner- 所有者的組 id 6 rdev device type, if inode device * - 設備類型,如果是 inode 設備的話 7 size size in bytes - 文件大小的字節數 8 atime time of last access (unix timestamp) - 上次訪問時間(Unix 時間戳) 9 mtime time of last modification (unix timestamp) - 上次修改時間(Unix 時間戳) 10 ctime time of last change (unix timestamp) - 上次改變時間(Unix 時間戳) 11 blksize blocksize of filesystem IO * - 文件系統 IO 的塊大小 12 blocks number of blocks allocated - 所占據塊的數目 * Windows 下總是 0。
* - 僅在支持 st_blksize 類型的系統下有效。其它系統(如 Windows)返回 -1。
如果出錯,stat() 返回 FALSE
。
Note: 因為 PHP 的整數類型是有符號整型而且很多平臺使用 32 位整型,對 2GB 以上的文件,一些文件系統函數可能返回無法預期的結果 。
錯誤/異常
錯誤時會產生 E_WARNING
級別的錯誤。
更新日志
版本 說明 4.0.6 返回一個數組包含有文件的統計信息,該數組具有以下列出的單元,數組下標從零開始。除了數字索引之外自還可以通過關聯索引來訪問。
范例
Example #1 stat() 例子
<?php
/* Get file stat */
$stat = stat('C:phpphp.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'];
?>
Example #2 Using stat() information together with touch()
<?php
/* Get file stat */
$stat = stat('C:phpphp.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...';
}
}
?>
注釋
Note:
注意:不同文件系統對時間的判斷方法可能是不相同的。
Note: 此函數的結果會被緩存。參見 clearstatcache() 以獲得更多細節。
Tip自 PHP 5.0.0 起, 此函數也用于某些 URL 包裝器。請參見 支持的協議和封裝協議以獲得支持 stat() 系列函數功能的包裝器列表。
參見
lstat() - 給出一個文件或符號連接的信息 fstat() - 通過已打開的文件指針取得文件信息 filemtime() - 取得文件修改時間 filegroup() - 取得文件的組