The stat() function returns information about a file.
Note − The results of the stat() function differs from server to server.
The function returns an array with the below given elements.
- [0] or [dev] - Device number
- [1] or [ino] - Inode number
- [2] or [mode] - Inode protection mode
- [3] or [nlink] - Number of links
- [4] or [uid] - User ID of owner
- [5] or [gid] - Group ID of owner
- [6] or [rdev] - Inode device type
- [7] or [size] - Size in bytes
- [8] or [atime] - Last access time as Unix timestamp
- [9] or [mtime] - Last modified time as Unix timestamp
- [10] or [ctime] - Last inode change time as Unix timestamp
- [11] or [blksize] - Blocksize of filesystem IO
- [12] or [blocks] - Number of blocks allocated
Syntax
stat(file_path)
Parameters
file_path − The path of the file to check.
Return
The lstat() function returns the elements shown above.
Example
<?php print_r(stat("demo.txt")); ?>
Output
Array ( [0] => 0 [1] => 0 [2] => 33206 [3] => 1 [4] => 0 [5] => 0 [6] => 0 [7] => 120 [8] => 17128173529 [9] => 1984185875 [10] => 1294322653 [11] => -1 [12] => -1 [dev] => 0 [ino] => 0 [mode] => 33206 [nlink] => 1 [uid] => 0 [gid] => 0 [rdev] => 0 [size] => 120 [atime] => 1718173529 [mtime] => 1984185875 [ctime] => 1294322653 [blksize] => -1 [blocks] => -1 )
Let us see another example.
Example
<?php $stat = stat('new.txt'); echo 'File mode = ' .$stat['mode']; echo '<br />Last Modification time of the file = ' .$stat['mtime']; ?>
Output
File mode = 33206 Last Modification time of the file = 1241387935