php fstat,PHP fstat( )用法及代码示例

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:

// 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:

// 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

)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值