fstat

(PHP 4, PHP 5)

fstat -- 通过已打开的文件指针取得文件信息

说明

array fstat ( resource handle )

获取由文件指针 handle 所打开文件的统计信息。本函数和 stat() 函数相似,除了它是作用于已打开的文件指针而不是文件名。

返回一个数组具有该文件的统计信息,该数组的格式详细说明于手册中 stat() 页面里。

例子 1. fstat() 例子

<?php

// 打开文件
$fp = fopen("/etc/passwd", "r");

// 取得统计信息
$fstat = fstat($fp);

// 关闭文件
fclose($fp);

// 只显示关联数组部分
print_r(array_slice($fstat, 13));

?>

上例的输出类似于:

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
)

注: 本函数不能作用于远程文件,被检查的文件必须通过服务器的文件系统访问。


add a note add a note User Contributed Notes
mordae at mordae dot net
29-Jan-2006 11:12
dom at dodgydom dot com wrote:
Best way i found was to open the url into $data and make a temporary file with the contents of $data then get the fstats on the temporary file :).

OMG why? The only thing that will remain is the file size. You also download up to 1G file, which probably is not what you want.

To get size use PHP's function filesize() with URL wrappers or ask yourself via HTTP.
sheran at comtrust dot co dot ae
22-Feb-2001 09:14
On Windows NT the typical array element names for the fstat function are:

dev
ino
mode
nlink
uid
gid
size
atime
mtime
ctime
jason at inetgurs dot net
15-Nov-2000 11:01
Currently fstat() is indexed by name instead of by number like stat().

Example: $s_array=fstat($fp); print $s_array["mtime"];fclose($fp);