2010-03-28 22:10:10 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 07:05:15 +00:00
|
|
|
<!-- $Revision$ -->
|
2007-06-20 22:25:43 +00:00
|
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.stat">
|
2007-02-03 08:13:44 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>stat</refname>
|
|
|
|
<refpurpose>Gives information about a file</refpurpose>
|
|
|
|
</refnamediv>
|
2007-06-16 01:17:14 +00:00
|
|
|
|
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2007-02-03 08:13:44 +00:00
|
|
|
<methodsynopsis>
|
|
|
|
<type>array</type><methodname>stat</methodname>
|
|
|
|
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
|
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
|
|
|
Gathers the statistics of the file named by
|
2007-06-16 01:17:14 +00:00
|
|
|
<parameter>filename</parameter>. If <parameter>filename</parameter> is a
|
|
|
|
symbolic link, statistics are from the file itself, not the symlink.
|
2007-02-03 08:13:44 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2007-06-16 01:17:14 +00:00
|
|
|
<function>lstat</function> is identical to <function>stat</function>
|
|
|
|
except it would instead be based off the symlinks status.
|
2007-02-03 08:13:44 +00:00
|
|
|
</para>
|
2007-06-16 01:17:14 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
2007-02-03 08:13:44 +00:00
|
|
|
<para>
|
2007-06-16 01:17:14 +00:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>filename</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Path to the file.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2007-02-03 08:13:44 +00:00
|
|
|
</para>
|
2007-06-16 01:17:14 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
2007-02-03 08:13:44 +00:00
|
|
|
<para>
|
|
|
|
<table>
|
|
|
|
<title><function>stat</function> and <function>fstat</function> result
|
|
|
|
format</title>
|
|
|
|
<tgroup cols="3">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Numeric</entry>
|
|
|
|
<entry>Associative (since PHP 4.0.6)</entry>
|
|
|
|
<entry>Description</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>0</entry>
|
|
|
|
<entry>dev</entry>
|
|
|
|
<entry>device number</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>1</entry>
|
|
|
|
<entry>ino</entry>
|
2008-08-19 13:03:09 +00:00
|
|
|
<entry>inode number *</entry>
|
2007-02-03 08:13:44 +00:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>2</entry>
|
|
|
|
<entry>mode</entry>
|
|
|
|
<entry>inode protection mode</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>3</entry>
|
|
|
|
<entry>nlink</entry>
|
|
|
|
<entry>number of links</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>4</entry>
|
|
|
|
<entry>uid</entry>
|
2008-08-19 13:03:09 +00:00
|
|
|
<entry>userid of owner *</entry>
|
2007-02-03 08:13:44 +00:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>5</entry>
|
|
|
|
<entry>gid</entry>
|
2008-08-19 13:03:09 +00:00
|
|
|
<entry>groupid of owner *</entry>
|
2007-02-03 08:13:44 +00:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>6</entry>
|
|
|
|
<entry>rdev</entry>
|
2008-07-08 01:17:41 +00:00
|
|
|
<entry>device type, if inode device</entry>
|
2007-02-03 08:13:44 +00:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>7</entry>
|
|
|
|
<entry>size</entry>
|
|
|
|
<entry>size in bytes</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>8</entry>
|
|
|
|
<entry>atime</entry>
|
|
|
|
<entry>time of last access (Unix timestamp)</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>9</entry>
|
|
|
|
<entry>mtime</entry>
|
|
|
|
<entry>time of last modification (Unix timestamp)</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>10</entry>
|
|
|
|
<entry>ctime</entry>
|
|
|
|
<entry>time of last inode change (Unix timestamp)</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>11</entry>
|
|
|
|
<entry>blksize</entry>
|
2008-08-19 13:03:09 +00:00
|
|
|
<entry>blocksize of filesystem IO **</entry>
|
2007-02-03 08:13:44 +00:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>12</entry>
|
|
|
|
<entry>blocks</entry>
|
2009-11-20 11:04:26 +00:00
|
|
|
<entry>number of 512-byte blocks allocated **</entry>
|
2007-02-03 08:13:44 +00:00
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
2008-08-19 13:03:09 +00:00
|
|
|
* On Windows this will always be 0.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
** Only valid on systems supporting the st_blksize type - other
|
2007-02-03 08:13:44 +00:00
|
|
|
systems (e.g. Windows) return -1.
|
|
|
|
</para>
|
2007-06-16 01:17:14 +00:00
|
|
|
<para>
|
|
|
|
In case of error, <function>stat</function> returns &false;.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
2003-11-29 16:39:55 +00:00
|
|
|
|
2007-06-16 01:17:14 +00:00
|
|
|
<refsect1 role="errors">
|
|
|
|
&reftitle.errors;
|
|
|
|
<para>
|
|
|
|
Upon failure, an <constant>E_WARNING</constant> is emitted.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
2007-02-03 08:13:44 +00:00
|
|
|
|
2007-06-16 01:17:14 +00:00
|
|
|
<refsect1 role="changelog">
|
|
|
|
&reftitle.changelog;
|
|
|
|
<para>
|
|
|
|
<informaltable>
|
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>&Version;</entry>
|
|
|
|
<entry>&Description;</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>4.0.6</entry>
|
|
|
|
<entry>
|
|
|
|
In addition to returning these attributes in a numeric array, they
|
|
|
|
can be accessed with associative indices, as noted next to each
|
|
|
|
parameter
|
|
|
|
</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</informaltable>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2008-08-31 01:30:39 +00:00
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>stat</function> example</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
/* Get file stat */
|
|
|
|
$stat = stat('C:\php\php.exe');
|
|
|
|
|
|
|
|
/*
|
2010-01-15 14:40:44 +00:00
|
|
|
* Print file access time, this is the same
|
2008-08-31 01:30:39 +00:00
|
|
|
* as calling fileatime()
|
|
|
|
*/
|
|
|
|
echo 'Access time: ' . $stat['atime'];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print file modification time, this is the
|
|
|
|
* same as calling filemtime()
|
|
|
|
*/
|
|
|
|
echo 'Modification time: ' . $stat['mtime'];
|
|
|
|
|
|
|
|
/* Print the device number */
|
|
|
|
echo 'Device number: ' . $stat['dev'];
|
2010-01-15 14:40:44 +00:00
|
|
|
?>
|
2008-08-31 01:30:39 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title>Using <function>stat</function> information together with <function>touch</function></title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
/* Get file stat */
|
2010-01-03 21:47:39 +00:00
|
|
|
$stat = stat('C:\php\php.exe');
|
2008-08-31 01:30:39 +00:00
|
|
|
|
2010-01-03 21:47:39 +00:00
|
|
|
/* Did we failed to get stat information? */
|
|
|
|
if (!$stat) {
|
|
|
|
echo 'stat() call failed...';
|
|
|
|
} else {
|
2008-08-31 22:45:31 +00:00
|
|
|
/*
|
|
|
|
* We want the access time to be 1 week
|
|
|
|
* before the current access time.
|
|
|
|
*/
|
2010-09-01 22:59:25 +00:00
|
|
|
$atime = strtotime('-1 week', $stat['atime']);
|
2008-08-31 01:30:39 +00:00
|
|
|
|
2008-08-31 22:45:31 +00:00
|
|
|
/* Touch the file */
|
2010-01-03 21:47:39 +00:00
|
|
|
if (!touch('some_file.txt', time(), $atime)) {
|
2008-08-31 22:45:31 +00:00
|
|
|
echo 'Failed to touch file...';
|
2010-01-03 21:47:39 +00:00
|
|
|
} else {
|
|
|
|
echo 'touch() returned success...';
|
2008-08-31 22:45:31 +00:00
|
|
|
}
|
2008-08-31 01:30:39 +00:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2007-06-16 01:17:14 +00:00
|
|
|
<refsect1 role="notes">
|
|
|
|
&reftitle.notes;
|
2008-08-25 04:22:37 +00:00
|
|
|
¬e.filesystem-time-res;
|
2007-06-16 01:17:14 +00:00
|
|
|
¬e.clearstatcache;
|
2007-02-03 08:13:44 +00:00
|
|
|
&tip.fopen-wrapper.stat;
|
2007-06-16 01:17:14 +00:00
|
|
|
</refsect1>
|
2007-02-03 08:13:44 +00:00
|
|
|
|
2007-06-16 01:17:14 +00:00
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
2007-02-03 08:13:44 +00:00
|
|
|
<para>
|
2007-06-16 01:17:14 +00:00
|
|
|
<simplelist>
|
|
|
|
<member><function>lstat</function></member>
|
|
|
|
<member><function>fstat</function></member>
|
|
|
|
<member><function>filemtime</function></member>
|
|
|
|
<member><function>filegroup</function></member>
|
|
|
|
</simplelist>
|
2007-02-03 08:13:44 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
2007-06-16 01:17:14 +00:00
|
|
|
|
2007-02-03 08:13:44 +00:00
|
|
|
</refentry>
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2002-04-15 00:12:54 +00:00
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|