<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.filesystem.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.stat.php',
    1 => 'stat',
    2 => 'Gives information about a file',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Filesystem Functions',
  ),
  'prev' => 
  array (
    0 => 'function.set-file-buffer.php',
    1 => 'set_file_buffer',
  ),
  'next' => 
  array (
    0 => 'function.symlink.php',
    1 => 'symlink',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/filesystem/functions/stat.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.stat" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stat</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">stat</span> &mdash; <span class="dc-title">Gives information about a file</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.stat-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>stat</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$filename</code></span>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Gathers the statistics of the file named by
   <code class="parameter">filename</code>.  If <code class="parameter">filename</code> is a
   symbolic link, statistics are from the file itself, not the symlink.
   Prior to PHP 7.4.0, on Windows <abbr class="abbrev">NTS</abbr> builds the <code class="literal">size</code>,
   <code class="literal">atime</code>, <code class="literal">mtime</code> and <code class="literal">ctime</code>
   statistics have been from the symlink, in this case.
  </p>
  <p class="para">
   <span class="function"><a href="function.lstat.php" class="function">lstat()</a></span> is identical to <span class="function"><strong>stat()</strong></span>
   except it would instead be based off the symlinks status.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stat-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       Path to the file.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stat-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   <table class="doctable table">
    <caption><strong><span class="function"><strong>stat()</strong></span> and <span class="function"><a href="function.fstat.php" class="function">fstat()</a></span> result
     format</strong></caption>
    
     <thead>
      <tr>
       <th>Numeric</th>
       <th>Associative</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>0</td>
       <td>dev</td>
       <td>device number ***</td>
      </tr>

      <tr>
       <td>1</td>
       <td>ino</td>
       <td>inode number ****</td>
      </tr>

      <tr>
       <td>2</td>
       <td>mode</td>
       <td>inode protection mode *****</td>
      </tr>

      <tr>
       <td>3</td>
       <td>nlink</td>
       <td>number of links</td>
      </tr>

      <tr>
       <td>4</td>
       <td>uid</td>
       <td>userid of owner *</td>
      </tr>

      <tr>
       <td>5</td>
       <td>gid</td>
       <td>groupid of owner *</td>
      </tr>

      <tr>
       <td>6</td>
       <td>rdev</td>
       <td>device type, if inode device</td>
      </tr>

      <tr>
       <td>7</td>
       <td>size</td>
       <td>size in bytes</td>
      </tr>

      <tr>
       <td>8</td>
       <td>atime</td>
       <td>time of last access (Unix timestamp)</td>
      </tr>

      <tr>
       <td>9</td>
       <td>mtime</td>
       <td>time of last modification (Unix timestamp)</td>
      </tr>

      <tr>
       <td>10</td>
       <td>ctime</td>
       <td>time of last inode change (Unix timestamp)</td>
      </tr>

      <tr>
       <td>11</td>
       <td>blksize</td>
       <td>blocksize of filesystem IO **</td>
      </tr>

      <tr>
       <td>12</td>
       <td>blocks</td>
       <td>number of 512-byte blocks allocated **</td>
      </tr>

     </tbody>
    
   </table>

  </p>
  <p class="para">
   * On Windows this will always be <code class="literal">0</code>.
  </p>
  <p class="para">
   ** Only valid on systems supporting the st_blksize type - other
   systems (e.g. Windows) return <code class="literal">-1</code>.
  </p>
  <p class="para">
   *** On Windows, as of PHP 7.4.0, this is the serial number of the volume that contains the file,
   which is a 64-bit <em>unsigned</em> integer, so may overflow.
   Previously, it was the numeric representation of the drive letter (e.g. <code class="literal">2</code>
   for <code class="literal">C:</code>) for <span class="function"><strong>stat()</strong></span>, and <code class="literal">0</code> for
   <span class="function"><a href="function.lstat.php" class="function">lstat()</a></span>.
  </p>
  <p class="para">
   **** On Windows, as of PHP 7.4.0, this is the identifier associated with the file,
   which is a 64-bit <em>unsigned</em> integer, so may overflow.
   Previously, it was always <code class="literal">0</code>.
  </p>
  <p class="para">
   ***** On Windows, the writable permission bit is set according to the read-only
   file attribute, and the same value is reported for all users, group and owner.
   The ACL is not taken into account, contrary to <span class="function"><a href="function.is-writable.php" class="function">is_writable()</a></span>.
  </p>
  <p class="para">
  The value of <code class="literal">mode</code> contains information read by several functions. 
  When written in octal, starting from the right, the first three digits are returned by
  <span class="function"><a href="function.chmod.php" class="function">chmod()</a></span>. The next digit is ignored by PHP. The next two digits indicate
  the file type:
   <table class="doctable table">
    <caption><strong><code class="literal">mode</code> file types</strong></caption>
    
     <thead>
      <tr>
       <th><code class="literal">mode</code> in octal</th>
       <th>Meaning</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td><code class="literal">0140000</code></td>
       <td>socket</td>
      </tr>

      <tr>
       <td><code class="literal">0120000</code></td>
       <td>link</td>
      </tr>

      <tr>
       <td><code class="literal">0100000</code></td>
       <td>regular file</td>
      </tr>

      <tr>
       <td><code class="literal">0060000</code></td>
       <td>block device</td>
      </tr>

      <tr>
       <td><code class="literal">0040000</code></td>
       <td>directory</td>
      </tr>

      <tr>
       <td><code class="literal">0020000</code></td>
       <td>character device</td>
      </tr>

      <tr>
       <td><code class="literal">0010000</code></td>
       <td>fifo</td>
      </tr>

     </tbody>
    
   </table>

   So for example a regular file could be <code class="literal">0100644</code> and a directory could be
   <code class="literal">0040755</code>.
  </p>
  <p class="para">
   In case of error, <span class="function"><strong>stat()</strong></span> returns <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">
    Because PHP&#039;s integer type is signed and many platforms use 32bit integers,
    some filesystem functions may return unexpected results for files which
    are larger than 2GB.
   </span></p></blockquote>
 </div>


 <div class="refsect1 errors" id="refsect1-function.stat-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   Upon failure, an <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> is emitted.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.stat-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>7.4.0</td>
      <td>
       On Windows, the device number is now the serial number of the volume that
       contains the file, and the inode number is the identifier associated with the file.
      </td>
     </tr>

     <tr>
      <td>7.4.0</td>
      <td>
       The <code class="literal">size</code>, <code class="literal">atime</code>, <code class="literal">mtime</code> and
       <code class="literal">ctime</code> statistics of symlinks are always those of the target.
       This was previously not the case for <abbr class="abbrev">NTS</abbr> builds on Windows.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.stat-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>stat()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/* Get file stat */<br /></span><span style="color: #0000BB">$stat </span><span style="color: #007700">= </span><span style="color: #0000BB">stat</span><span style="color: #007700">(</span><span style="color: #DD0000">'C:\php\php.exe'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*<br /> * Print file access time, this is the same <br /> * as calling fileatime()<br /> */<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">'Access time: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #DD0000">'atime'</span><span style="color: #007700">];<br /><br /></span><span style="color: #FF8000">/*<br /> * Print file modification time, this is the <br /> * same as calling filemtime()<br /> */<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">'Modification time: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #DD0000">'mtime'</span><span style="color: #007700">];<br /><br /></span><span style="color: #FF8000">/* Print the device number */<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">'Device number: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #DD0000">'dev'</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Example #2 Using <span class="function"><strong>stat()</strong></span> information together with <span class="function"><a href="function.touch.php" class="function">touch()</a></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/* Get file stat */<br /></span><span style="color: #0000BB">$stat </span><span style="color: #007700">= </span><span style="color: #0000BB">stat</span><span style="color: #007700">(</span><span style="color: #DD0000">'C:\php\php.exe'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Did we failed to get stat information? */<br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">$stat</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">'stat() call failed...'</span><span style="color: #007700">;<br />} else {<br />    </span><span style="color: #FF8000">/*<br />     * We want the access time to be 1 week <br />     * after the current access time.<br />     */<br />    </span><span style="color: #0000BB">$atime </span><span style="color: #007700">= </span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #DD0000">'atime'</span><span style="color: #007700">] + </span><span style="color: #0000BB">604800</span><span style="color: #007700">;<br /><br />    </span><span style="color: #FF8000">/* Touch the file */<br />    </span><span style="color: #007700">if (!</span><span style="color: #0000BB">touch</span><span style="color: #007700">(</span><span style="color: #DD0000">'some_file.txt'</span><span style="color: #007700">, </span><span style="color: #0000BB">time</span><span style="color: #007700">(), </span><span style="color: #0000BB">$atime</span><span style="color: #007700">)) {<br />        echo </span><span style="color: #DD0000">'Failed to touch file...'</span><span style="color: #007700">;<br />    } else {<br />        echo </span><span style="color: #DD0000">'touch() returned success...'</span><span style="color: #007700">;<br />    }<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.stat-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">Note that time resolution may differ
from one file system to another.</p></p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">The results of this
function are cached. See <span class="function"><a href="function.clearstatcache.php" class="function">clearstatcache()</a></span> for
more details.</span></p></blockquote>
  <div class="tip"><strong class="tip">Tip</strong><p class="simpara">As of PHP 5.0.0, this function
can also be used with <em>some</em> URL wrappers.  Refer to
<a href="wrappers.php" class="xref">Supported Protocols and Wrappers</a> to determine which wrappers support
<span class="function"><strong>stat()</strong></span> family of functionality.</p></div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.stat-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.lstat.php" class="function" rel="rdfs-seeAlso">lstat()</a> - Gives information about a file or symbolic link</span></li>
    <li><span class="function"><a href="function.fstat.php" class="function" rel="rdfs-seeAlso">fstat()</a> - Gets information about a file using an open file pointer</span></li>
    <li><span class="function"><a href="function.filemtime.php" class="function" rel="rdfs-seeAlso">filemtime()</a> - Gets file modification time</span></li>
    <li><span class="function"><a href="function.filegroup.php" class="function" rel="rdfs-seeAlso">filegroup()</a> - Gets file group</span></li>
    <li><span class="classname"><a href="class.splfileinfo.php" class="classname">SplFileInfo</a></span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>