|
|
 |
stat (PHP 3, PHP 4 ) stat -- Gives information about a file Descriptionarray stat ( string filename)
Gathers the statistics of the file named by filename.
Returns an array with the statistics of the file with the
following elements:
device inode inode protection mode number of links user id of owner group id owner device type if inode device * size in bytes time of last access time of last modification time of last change blocksize for filesystem I/O * number of blocks allocated
* - only valid on systems supporting the st_blksize type--other
systems (i.e. Windows) return -1.
Returns FALSE in case of error.
stat() cannot be used on remote files.
The results of this function are cached. See
clearstatcache() for more details.
User Contributed Notes stat |
 |
ian@eiloart.com
23-Jul-1999 01:52 |
|
Here's what the UNIX man page on stat has to say about the difference
between a file change and a file modification:
st_mtime Time
when data was last modified. Changed by the following functions:
creat(), mknod(), pipe(), utime(), and write(2).
st_ctime Time
when file status was last changed. Changed by the following
functions: chmod(), chown(), creat(), link(2), mknod(), pipe(), unlink(2),
utime(), and write().
So a modification is a change in the data,
whereas a change also happens if you modify file permissions and so on.
|
|
esmith@schicktech.com
07-Mar-2000 04:53 |
|
Note that in the docs above, the array is zero based. I scratched my head a
couple of times, before decreasing each item by one. ie - stat for file
size is actually 7 !
|
|
ngreen@neilsmachine.com
11-Nov-2000 06:00 |
|
When you get a time from stat, like the date modified, you'll get a
timestamp returned. You can use date() to convert it into a human readable
format:
$modified = stat("yourfile.html");
echo
date("l, F dS",$modified[9]);
|
|
lonewolf@WPI.edu
14-May-2001 04:36 |
|
This function returns NULL if an invalid filename is entered. This
function also does not work on remote files.
|
|
scott@graphictype.com
22-Jun-2001 05:27 |
|
Remember that arrays are numbered from 0, whereas this document page is
numbered from 1.
$s = stat($file);
$bytes =
$s[7];
*not* $s[8], as you might think from quickly glancing at
the list of elements that stat() returns.
|
|
ashley@dcs.warwick.ac.uk
05-Apr-2002 12:10 |
|
I think "3. inode protection mode" is incorrect. Value 2 in the
array actually seems to actually correspond to st_mode from a C stat()
call, ie what the UNIX man pages call file "mode", or what I
would call "file type".
At the moment, I'm trying to
reliably detect files that are not regular files or directories. I don't
seem to be able to do this with is_file and is_dir (this seems to mess up
on special files, eg named pipes).
What I have constructed below
seems to do what I want, but careful if you want to reuse it: it isn't well
tested yet and the constant values are from a system file on Solaris
8.
// from /usr/include/sys/stat.h -- careful: probably only valid
on Solaris define("S_IFMT",
0xF000); define("S_IFREG",
0x8000); define("S_IFDIR", 0x4000);
if ((s =
lstat($fileName)) == false) die("ERROR: failed to stat file
$fileName");
$type = s[2] & S_IFMT; if (($type !=
S_IFREG) && ($type != S_IFDIR)) die("ERROR: expecting file
or directory and found something else at $fileName");
|
|
jboonstra@boonstras.com
05-Jun-2002 12:02 |
|
If you'd like to get information about a symlink, rather than the file it's
pointing to, use the lstat() function instead. Took me a little while to
figure that out...
|
|
jstuckeyATthehousecompanyDOTcom
09-Jul-2002 10:27 |
|
it's probably more readable to just use the associative key instead of the
numeric index. it'll also save you some head-scratching. for
instance:
$info = stat('path/file'); echo $info[4]; echo
$info['uid'];
will both output the same thing. using the print_r()
function is really pretty awesome for error-testing arrays just like this
one. just be sure to surround it in <PRE> tags if you are sending
output to a browser.
|
|
haiko at hebig dot org
03-Aug-2002 02:51 |
|
As jstuckey says, "it's probably more readable to just use the
associative key instead of the numeric index." So for the sake of
completeness, the associative keys are:
[0] [dev] [1] [ino]
[2] [mode] [3] [nlink] [4] [uid] [5] [gid] [6] [rdev]
[7] [size] [8] [atime] [9] [mtime] [10] [ctime] [11]
[blksize] [12] [blocks]
|
|
 |
| |