The fstat() function returns information about an open file. This function returns an array of information containing the following data:
[dev] - Device number[ino] - Inode number[mode] - Inode protection mode[nlink] - Number of links[uid] - User ID of owner[gid] - Group ID of owner[rdev] - Inode device type[size] - Size in bytes[atime] - Last access (as Unix timestamp)[mtime] - Last modified (as Unix timestamp)[ctime] - Last inode change (as Unix timestamp)[blksize] - Blocksize of filesystem IO (if supported)[blocks] - Number of blocks allocatedIn order to use this function, it is important for the file to be open.
fstat(resource $stream): array|false
stream: A file stream associated with an open file for which the information is required.
This function returns an array containing the information. If the function does not execute properly, it returns false.
Let’s have a look at the usage of this function. In this example, we create a file hello.txt, pass it to the function fstat(), and look at the output from the function. Keep in mind that we must open the file in order to use this method.
<?php$file = fopen("hello.txt","r");print_r(fstat($file));fclose($file);?>
Free Resources