uTools-Manuals/docs/php/stat.html
2019-04-28 19:00:34 +08:00

257 lines
12 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>给出文件的信息</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.stat" class="refentry">
<div class="refnamediv">
<h1 class="refname">stat</h1>
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</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">string</span> <code class="parameter">$filename</code></span>
) : <span class="type">array</span></div>
<p class="para rdfs-comment">
获取由 <code class="parameter">filename</code> 指定的文件的统计信息。如果
<code class="parameter">filename</code>
是符号连接,则统计信息是关于被连接文件本身的,而不是符号连接。
</p>
<p class="para">
<span class="function"><a href="lstat.html" 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="fstat.html" class="function">fstat()</a></span> 返回格式</strong></caption>
<thead>
<tr>
<th>数字下标</th>
<th>关联键名(自 PHP 4.0.6</th>
<th>说明</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 - inode 号码</td>
</tr>
<tr>
<td>2</td>
<td>mode</td>
<td>inode protection mode - inode 保护模式</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 - 所有者的用户 id</td>
</tr>
<tr>
<td>5</td>
<td>gid</td>
<td>groupid of owner- 所有者的组 id</td>
</tr>
<tr>
<td>6</td>
<td>rdev</td>
<td>device type, if inode device * - 设备类型,如果是 inode 设备的话</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) - 上次访问时间Unix 时间戳)</td>
</tr>
<tr>
<td>9</td>
<td>mtime</td>
<td>time of last modification (unix timestamp) - 上次修改时间Unix 时间戳)</td>
</tr>
<tr>
<td>10</td>
<td>ctime</td>
<td>time of last change (unix timestamp) - 上次改变时间Unix 时间戳)</td>
</tr>
<tr>
<td>11</td>
<td>blksize</td>
<td>blocksize of filesystem IO * - 文件系统 IO 的块大小</td>
</tr>
<tr>
<td>12</td>
<td>blocks</td>
<td>number of blocks allocated - 所占据块的数目</td>
</tr>
</tbody>
</table>
* Windows 下总是 0。
</p>
<p class="para">
* - 仅在支持 st_blksize 类型的系统下有效。其它系统(如 Windows返回 -1。
</p>
<p class="para">
如果出错,<span class="function"><strong>stat()</strong></span> 返回 <strong><code>FALSE</code></strong>
</p>
<blockquote class="note"><p><strong class="note">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>E_WARNING</code></strong> 级别的错误。
</p>
</div>
<div class="refsect1 changelog" id="refsect1-function.stat-changelog">
<h3 class="title">更新日志</h3>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>4.0.6</td>
<td>
返回一个数组包含有文件的统计信息,该数组具有以下列出的单元,数组下标从零开始。除了数字索引之外自还可以通过关联索引来访问。
</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.stat-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-2844">
<p><strong>Example #1 <span class="function"><strong>stat()</strong></span> 例子</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Get&nbsp;file&nbsp;stat&nbsp;*/<br /></span><span style="color: #0000BB">$stat&nbsp;</span><span style="color: #007700">=&nbsp;</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 />&nbsp;*&nbsp;Print&nbsp;file&nbsp;access&nbsp;time,&nbsp;this&nbsp;is&nbsp;the&nbsp;same&nbsp;<br />&nbsp;*&nbsp;as&nbsp;calling&nbsp;fileatime()<br />&nbsp;*/<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'Access&nbsp;time:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</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 />&nbsp;*&nbsp;Print&nbsp;file&nbsp;modification&nbsp;time,&nbsp;this&nbsp;is&nbsp;the&nbsp;<br />&nbsp;*&nbsp;same&nbsp;as&nbsp;calling&nbsp;filemtime()<br />&nbsp;*/<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'Modification&nbsp;time:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</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">/*&nbsp;Print&nbsp;the&nbsp;device&nbsp;number&nbsp;*/<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'Device&nbsp;number:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</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>
</pre></div>
</div>
</div>
</p>
<p class="para">
<div class="example" id="example-2845">
<p><strong>Example #2 Using <span class="function"><strong>stat()</strong></span> information together with <span class="function"><a href="touch.html" class="function">touch()</a></span></strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Get&nbsp;file&nbsp;stat&nbsp;*/<br /></span><span style="color: #0000BB">$stat&nbsp;</span><span style="color: #007700">=&nbsp;</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">/*&nbsp;Did&nbsp;we&nbsp;failed&nbsp;to&nbsp;get&nbsp;stat&nbsp;information?&nbsp;*/<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">$stat</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'stat()&nbsp;call&nbsp;failed...'</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;We&nbsp;want&nbsp;the&nbsp;access&nbsp;time&nbsp;to&nbsp;be&nbsp;1&nbsp;week&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;after&nbsp;the&nbsp;current&nbsp;access&nbsp;time.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$atime&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #DD0000">'atime'</span><span style="color: #007700">]&nbsp;+&nbsp;</span><span style="color: #0000BB">604800</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;Touch&nbsp;the&nbsp;file&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">touch</span><span style="color: #007700">(</span><span style="color: #DD0000">'some_file.txt'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">time</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">$atime</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Failed&nbsp;to&nbsp;touch&nbsp;file...'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'touch()&nbsp;returned&nbsp;success...'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></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">Note</strong>: <p class="para">注意:不同文件系统对时间的判断方法可能是不相同的。</p></p></blockquote>
<blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数的结果会被缓存。参见
<span class="function"><a href="clearstatcache.html" class="function">clearstatcache()</a></span> 以获得更多细节。</span></p></blockquote>
<div class="tip"><strong class="tip">Tip</strong><p class="simpara">自 PHP 5.0.0 起, 此函数也用于<em class="emphasis">某些</em>
URL 包装器。请参见 <a href="wrappers.html" 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 class="member"><span class="function"><a href="lstat.html" class="function" rel="rdfs-seeAlso">lstat()</a> - 给出一个文件或符号连接的信息</span></li>
<li class="member"><span class="function"><a href="fstat.html" class="function" rel="rdfs-seeAlso">fstat()</a> - 通过已打开的文件指针取得文件信息</span></li>
<li class="member"><span class="function"><a href="filemtime.html" class="function" rel="rdfs-seeAlso">filemtime()</a> - 取得文件修改时间</span></li>
<li class="member"><span class="function"><a href="filegroup.html" class="function" rel="rdfs-seeAlso">filegroup()</a> - 取得文件的组</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>