<?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 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.stat.php',
    1 => 'stat',
    2 => '给出文件的信息',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => '文件系统函数',
  ),
  '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' => 'zh',
    '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">给出文件的信息</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.stat-description">
  <h3 class="title">说明</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">
   获取由 <code class="parameter">filename</code> 指定的文件的统计信息。如果
   <code class="parameter">filename</code>
   是符号连接，则统计信息是关于被连接文件本身的，而不是符号连接。在 PHP 7.4.0
   之前，使用 Windows <abbr class="abbrev">NTS</abbr> 版本获取
   <code class="literal">size</code>、<code class="literal">atime</code>、<code class="literal">mtime</code>
   和 <code class="literal">ctime</code> 统计信息将从符号链接获取。
  </p>
  <p class="para">
   <span class="function"><a href="function.lstat.php" class="function">lstat()</a></span> 和 <span class="function"><strong>stat()</strong></span> 相同，只除了它会返回符号连接的状态。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stat-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       文件的路径。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stat-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <table class="doctable table">
    <caption><strong><span class="function"><strong>stat()</strong></span> 和 <span class="function"><a href="function.fstat.php" class="function">fstat()</a></span> 返回格式</strong></caption>
    
     <thead>
      <tr>
       <th>数字下标</th>
       <th>关联键名</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>0</td>
       <td>dev</td>
       <td>设备号 ***</td>
      </tr>

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

      <tr>
       <td>2</td>
       <td>mode</td>
       <td>inode 保护模式 *****</td>
      </tr>

      <tr>
       <td>3</td>
       <td>nlink</td>
       <td>连接数目</td>
      </tr>

      <tr>
       <td>4</td>
       <td>uid</td>
       <td>所有者的用户 id *</td>
      </tr>

      <tr>
       <td>5</td>
       <td>gid</td>
       <td>所有者的组 id *</td>
      </tr>

      <tr>
       <td>6</td>
       <td>rdev</td>
       <td>设备类型，如果是 inode 设备的话</td>
      </tr>

      <tr>
       <td>7</td>
       <td>size</td>
       <td>文件大小的字节数</td>
      </tr>

      <tr>
       <td>8</td>
       <td>atime</td>
       <td>上次访问时间（Unix 时间戳）</td>
      </tr>

      <tr>
       <td>9</td>
       <td>mtime</td>
       <td>上次修改时间（Unix 时间戳）</td>
      </tr>

      <tr>
       <td>10</td>
       <td>ctime</td>
       <td>上次 inodb 改变时间（Unix 时间戳）</td>
      </tr>

      <tr>
       <td>11</td>
       <td>blksize</td>
       <td>文件系统 IO 的块大小 **</td>
      </tr>

      <tr>
       <td>12</td>
       <td>blocks</td>
       <td>分配的 512 字节块数 **</td>
      </tr>

     </tbody>
    
   </table>

  </p>
  <p class="para">
   * Windows 下总是 <code class="literal">0</code>。
  </p>
  <p class="para">
   * - 仅在支持 st_blksize 类型的系统下有效。其它系统（如 Windows）返回 <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">
   **** 在 Windows 上，自 PHP 7.4.0 起，这是跟文件相关的标识符，因为是64位
   <em>unsigned</em> 整数，因此可能会溢出。之前始终为 <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">
  <code class="literal">mode</code> 的值包含几个函数读取到的信息。当用八进制编写时，从右开始，前三位由
  <span class="function"><a href="function.chmod.php" class="function">chmod()</a></span> 返回。PHP 忽略下一个数字。接下来的两位数字表示文件类型：
   <table class="doctable table">
    <caption><strong><code class="literal">mode</code> 文件类型</strong></caption>
    
     <thead>
      <tr>
       <th>八进制表示 <code class="literal">mode</code></th>
       <th>含义</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>常规文件</td>
      </tr>

      <tr>
       <td><code class="literal">0060000</code></td>
       <td>块设备</td>
      </tr>

      <tr>
       <td><code class="literal">0040000</code></td>
       <td>目录</td>
      </tr>

      <tr>
       <td><code class="literal">0020000</code></td>
       <td>字符设备</td>
      </tr>

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

     </tbody>
    
   </table>

   例如普通文件可能是 <code class="literal">0100644</code>，目录可能是 <code class="literal">0040755</code>。
  </p>
  <p class="para">
   如果出错，<span class="function"><strong>stat()</strong></span> 返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">
因为 PHP 的整数类型是有符号整型而且很多平台使用 32 位整型，对 2GB
以上的文件，一些文件系统函数可能返回无法预期的结果。</span></p></blockquote>
 </div>


 <div class="refsect1 errors" id="refsect1-function.stat-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   错误时会产生 <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> 级别的错误。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.stat-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</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">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>stat()</strong></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">/*<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>示例 #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">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: <p class="para">注意：不同文件系统对时间的判断方法可能是不相同的。</p></p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">此函数的结果会被缓存。参见
<span class="function"><a href="function.clearstatcache.php" class="function">clearstatcache()</a></span> 以获得更多细节。</span></p></blockquote>
  <div class="tip"><strong class="tip">小技巧</strong><p class="simpara">自 PHP 5.0.0 起, 此函数也用于<em>某些</em>
URL 包装器。请参见 <a href="wrappers.php" class="xref">支持的协议和封装协议</a>以获得支持 <span class="function"><strong>stat()</strong></span> 系列函数功能的包装器列表。</p></div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.stat-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.lstat.php" class="function" rel="rdfs-seeAlso">lstat()</a> - 给出一个文件或符号连接的信息</span></li>
    <li><span class="function"><a href="function.fstat.php" class="function" rel="rdfs-seeAlso">fstat()</a> - 通过已打开的文件指针取得文件信息</span></li>
    <li><span class="function"><a href="function.filemtime.php" class="function" rel="rdfs-seeAlso">filemtime()</a> - 取得文件修改时间</span></li>
    <li><span class="function"><a href="function.filegroup.php" class="function" rel="rdfs-seeAlso">filegroup()</a> - 取得文件的组</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); ?>