In PHP, stat() returns detailed information about a file or folder, such as its size, permissions and last modified time.
The result is one array that holds everything the system knows about the file. Each value is available both by number and by name, so you can use $info['size'] or $info[7].
Syntax
Call stat() with the values you need. Start with this line.
PHP
$info = stat('report.txt');
Call
What it does
stat('report.txt')
Returns an array with size, mode, uid, mtime and other details.
stat('report.txt')['size']
Gets only the size of the file in bytes.
stat('missing.txt')
Returns false and raises a warning because the file does not exist.
The array contains these named keys: dev, ino, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime, blksize and blocks. The same values are also available by index from 0 to 12. PHP caches the result, so call clearstatcache() if the file changes during the script.
Library declarations
PHP
stat(string $filename): array|false
Parameters
Parameter
Description
filename
Required. The path to the file or folder. For symbolic links, stat() follows the link and reports on the target.
Return Value
Return Value
Description
array|false
Returns an array with file information, or false on failure. The array has both numeric and named keys.
PHP Examples
Example 1 — Read Size and Permissions
Create a small file and print its size and permissions with stat().