★ wanayoo — archive 1999 http://fr.php.net/manual/cs/function.stat.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | reporting bugs | php.net sites | links 
search for in the  
previousset_file_buffersymlinknext
Last updated: Sun, 21 Jul 2002
view this page in Printer friendly version | English | Brazilian Portuguese | Chinese | Dutch | Finnish | French | German | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Turkish

stat

(PHP 3, PHP 4 )

stat -- Zjią»uje informace o souboru

Popis

array stat ( string filename)

Sbírá statistiky o souboru indentifikovaném názvem filename.

Vrací pole se statistikami souboru s těmito elementy:

  1. device

  2. inode

  3. inode protection mode

  4. number of links

  5. user id of owner

  6. group id owner

  7. device type if inode device *

  8. size in bytes

  9. time of last access

  10. time of last modification

  11. time of last change

  12. blocksize for filesystem I/O *

  13. 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
add a note about notes
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.

add a note about notes
previousset_file_buffersymlinknext
Last updated: Sun, 21 Jul 2002
show source | credits | stats | mirror sites:  
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by: nexen.net
Last updated: Tue Jul 30 05:05:42 2002 CEST