PHP stat() function
Definition and Usage
The stat() function returns information about the file.
Syntax
fstat(file)
Parameter | Description |
---|---|
file | Required. Specifies the file to be checked. |
Description
Obtained by file Statistics of the specified file. If file If it is a symbolic link, the statistics are about the file being linked to, not the symbolic link itself.
If an error occurs, stat() returns false and issues a warning.
The returned array contains file statistics, and the array has the following units listed, the array index starts from zero. Starting from PHP 4.0.6, it can also be accessed through associative indices in addition to numeric indices.
Return format of stat()
Numeric index | Associated key name (since PHP 4.0.6) | Description |
---|---|---|
0 | dev | Device name |
1 | ino | Number |
2 | mode | inode protection mode |
3 | nlink | Number of hard links |
4 | uid | User ID of the owner |
5 | gid | Group ID of the owner |
6 | rdev | Device type, if it is an inode device |
7 | size | Number of bytes in file size |
8 | atime | Last access time (Unix timestamp) |
9 | mtime | Last modified time (Unix timestamp) |
10 | ctime | Last change time (Unix timestamp) |
11 | blksize | Block size of file system IO |
12 | blocks | Number of blocks occupied |
Tips and Comments
Tip:lstat() Similar to stat(), the difference is that it returns the status of the symbolic link.
Note:The result of this function will be cached. Please use clearstatcache() to clear the cache.
Example
<?php $file = fopen("test.txt","r"); print_r(stat($file)); fclose($file); ?>
Output similar to:
Array ( [0] => 0 [1] => 0 [2] => 33206 [3] => 1 [4] => 0 [5] => 0 [6] => 0 [7] => 92 [8] => 1141633430 [9] => 1141298003 [10] => 1138609592 [11] => -1 [12] => -1 [dev] => 0 [ino] => 0 [mode] => 33206 [nlink] => 1 [uid] => 0 [gid] => 0 [rdev] => 0 [size] => 92 [atime] => 1141633430 [mtime] => 1141298003 [ctime] => 1138609592 [blksize] => -1 [blocks] => -1 )