<!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>Gives information about a file</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.set-file-buffer.html">set_file_buffer</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.symlink.html">symlink</a></div> <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.stat" class="refentry"> <div class="refnamediv"> <h1 class="refname">stat</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">stat</span> — <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="type">array</span> <span class="methodname"><strong>stat</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span> )</div> <p class="para rdfs-comment"> Gathers the statistics of the file named by <em><code class="parameter">filename</code></em>. If <em><code class="parameter">filename</code></em> is a symbolic link, statistics are from the file itself, not the symlink. </p> <p class="para"> <span class="function"><a href="function.lstat.html" 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> <span class="term"><em><code class="parameter">filename</code></em></span> <dd> <p class="para"> Path to the file. </p> </dd> </dt> </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.html" class="function">fstat()</a></span> result format</strong></caption> <thead> <tr> <th>Numeric</th> <th>Associative (since PHP 4.0.6)</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> * On Windows this will always be 0. </p> <p class="para"> ** Only valid on systems supporting the st_blksize type - other systems (e.g. Windows) return -1. </p> <p class="para"> In case of error, <span class="function"><strong>stat()</strong></span> returns <strong><code>FALSE</code></strong>. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> Because PHP'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>E_WARNING</code></strong> is emitted. </p> </div> <div class="refsect1 changelog" id="refsect1-function.stat-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>4.0.6</td> <td> In addition to returning these attributes in a numeric array, they can be accessed with associative indices, as noted next to each parameter </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.stat-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2431"> <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"><?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">?></span> </span> </code></div> </div> </div> </p> <p class="para"> <div class="example" id="example-2432"> <p><strong>Example #2 Using <span class="function"><strong>stat()</strong></span> information together with <span class="function"><a href="function.touch.html" class="function">touch()</a></span></strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?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">?></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.html" 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 class="emphasis">some</em> URL wrappers. Refer to <a href="wrappers.html" 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 class="member"> <span class="function"><a href="function.lstat.html" class="function" rel="rdfs-seeAlso">lstat()</a> - Gives information about a file or symbolic link</span></li> <li class="member"> <span class="function"><a href="function.fstat.html" class="function" rel="rdfs-seeAlso">fstat()</a> - Gets information about a file using an open file pointer</span></li> <li class="member"> <span class="function"><a href="function.filemtime.html" class="function" rel="rdfs-seeAlso">filemtime()</a> - Gets file modification time</span></li> <li class="member"> <span class="function"><a href="function.filegroup.html" class="function" rel="rdfs-seeAlso">filegroup()</a> - Gets file group</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.set-file-buffer.html">set_file_buffer</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.symlink.html">symlink</a></div> <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>