PHP中的fstat()函数是一个内置函数,用于返回有关打开文件的信息。文件名作为参数发送到fstat()函数,并且它返回包含以下元素的数组:
| 数字 | 名称 | 描述 |
|---|---|---|
| 0 | dev | Device number |
| 1 | ino | inode number* |
| 2 | mode | inode protection mode |
| 3 | nlink | number of links |
| 4 | uid | userid of owner* |
| 5 | gid | groupid of owner |
| 6 | rdev | device type, if inode device |
| 7 | size | size in bytes |
| 8 | atime | time of last access (Unix timestamp) |
| 9 | mtime | time of last modification (Unix timestamp) |
| 10 | ctime | time of last inode change (Unix timestamp) |
| 11 | blksize | blocksize of filesystem IO ** |
| 12 | blocks | number of 512-byte blocks allocated ** |
fstat()函数收集由文件指针句柄打开的文件的统计信息。 fstat()函数与stat()函数类似,不同之处在于它对打开的文件指针而不是文件名进行操作。
用法:
array fstat ( $file )
参数:PHP中的fstat()函数仅接受一个参数。
- $file:它是指定文件的必需参数。
返回值:成功返回带有上述元素的数组。
异常:
- 此函数的结果将因服务器而异。该数组可以包含数字索引,名称索引或两者。
- fstat()函数类似于stat()函数,不同之处在于必须使用该文件打开文件。
- 通过对文件的简单读取访问将不会更新atime元素。
以下示例程序旨在说明fstat()函数:
程序1:
<?php
// Opening a file
$myfile = fopen("gfg.txt", "r");
// printing the stats of the opened file
print_r(fstat($myfile));
// closing the file
fclose($myfile);
?>输出:
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 )
程序2:
<?php
// Opening a file
$myfile = fopen("gfg.txt", "r");
// printing the associative part of the output array
$mystat = fstat($myfile);
print_r(array_slice($mystat, 13));
// closing the file
fclose($myfile);
?>输出:
Array
(
[dev] => 771
[ino] => 488704
[mode] => 33188
[nlink] => 1
[uid] => 0
[gid] => 0
[rdev] => 0
[size] => 1114
[atime] => 1061067181
[mtime] => 1056136526
[ctime] => 1056136526
[blksize] => 4096
[blocks] => 8
)
参考: http://php.net/manual/en/function.fstat.php
相关用法
- PHP SplFileObject fstat()用法及代码示例
- p5.js str()用法及代码示例
- d3.js d3.min()用法及代码示例
- p5.js hex()用法及代码示例
- CSS url()用法及代码示例
- d3.js d3.hcl()用法及代码示例
- CSS rgb()用法及代码示例
- p5.js box()用法及代码示例
- p5.js value()用法及代码示例
- PHP pi( )用法及代码示例
- PHP pow( )用法及代码示例
- d3.js d3.rgb()用法及代码示例
注:本文由纯净天空筛选整理自Shubrodeep Banerjee大神的英文原创作品 PHP | fstat() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
