search for in the  
<fseekftell>
Last updated: Thu, 19 May 2005

fstat

(PHP 4, PHP 5)

fstat -- Gets information about a file using an open file pointer

Description

array fstat ( resource handle )

Gathers the statistics of the file opened by the file pointer handle. This function is similar to the stat() function except that it operates on an open file pointer instead of a filename.

Returns an array with the statistics of the file; the format of the array is described in detail on the stat() manual page.

Example 1. fstat() example

<?php

// open a file
$fp = fopen("/etc/passwd", "r");

// gather statistics
$fstat = fstat($fp);

// close the file
fclose($fp);

// print only the associative part
print_r(array_slice($fstat, 13));

?>

The above example will output something similar to:

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
)

Note: This function will not work on remote files as the file to be examined must be accessible via the servers filesystem.



User Contributed Notes
fstat
dom at dodgydom dot com
12-Feb-2003 10:33
Example for getting remote file stats.

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 :).

$url="http://www.testurl.com";
$fp=fopen($url,"r");
$data=fread($fp,"1000000");
fclose($fp);

$test_file="./temp_file.txt";
$fp_test=fopen($test_file,"w+");
$fp_write=fputs($fp_test,$data);
fclose($fp_test);

$stat_file='./temp_file.txt';
$test_fp=fopen($stat_file,"r");
$stats=fstat($test_fp);
fclose($test_fp);

print_r($stats);

Seems to work fine for me, If there is a quicker way i havn't found it yet.
sheran at comtrust dot co dot ae
21-Feb-2001 07: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
14-Nov-2000 09:01
Currently fstat() is indexed by name instead of by number like stat().

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

<fseekftell>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT