|
|
 |
stat (PHP 3, PHP 4 ) stat -- Zjią»uje informace o souboru Popisarray stat ( string filename)
Sbírá statistiky o souboru indentifikovaném názvem
filename.
Vrací pole se statistikami souboru s těmito elementy:
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
* - platné pouze na systémechs podporou typu st_blksize -- jinde
(např. na Windows) vrátí -1
Výsledek této funkce je cachován. Více informací - viz
clearstatcache().
User Contributed Notes stat |
 |
ian@eiloart.com
23-Jul-1999 02: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 05: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 07: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 05: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 06: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 01: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 01: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 11: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.
|
|
 |
 | |