<!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>Gets information about a file using an open file pointer</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.fseek.html">fseek</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.ftell.html">ftell</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.fstat" class="refentry"> <div class="refnamediv"> <h1 class="refname">fstat</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">fstat</span> — <span class="dc-title">Gets information about a file using an open file pointer</span></p> </div> <div class="refsect1 description" id="refsect1-function.fstat-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><strong>fstat</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$handle</code></span> )</div> <p class="para rdfs-comment"> Gathers the statistics of the file opened by the file pointer <em><code class="parameter">handle</code></em>. This function is similar to the <span class="function"><a href="function.stat.html" class="function">stat()</a></span> function except that it operates on an open file pointer instead of a filename. </p> </div> <div class="refsect1 parameters" id="refsect1-function.fstat-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">handle</code></em></span> <dd> <p class="para">A file system pointer <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span> that is typically created using <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span>.</p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.fstat-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an array with the statistics of the file; the format of the array is described in detail on the <span class="function"><a href="function.stat.html" class="function">stat()</a></span> manual page. </p> </div> <div class="refsect1 examples" id="refsect1-function.fstat-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2394"> <p><strong>Example #1 <span class="function"><strong>fstat()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">// open a file<br /></span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"/etc/passwd"</span><span style="color: #007700">, </span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// gather statistics<br /></span><span style="color: #0000BB">$fstat </span><span style="color: #007700">= </span><span style="color: #0000BB">fstat</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// close the file<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// print only the associative part<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">array_slice</span><span style="color: #007700">(</span><span style="color: #0000BB">$fstat</span><span style="color: #007700">, </span><span style="color: #0000BB">13</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Array ( [dev] => 771 [ino] => 488704 [mode] => 33188 [nlink] => 1 [uid] => 0 [gid] => 0 [rdev] => 0 [size] => 1114 [atime] => 1061067181 [mtime] => 1056136526 [ctime] => 1056136526 [blksize] => 4096 [blocks] => 8 ) </pre></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.fstat-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">This function will not work on <a href="features.remote-files.html" class="link">remote files</a> as the file to be examined must be accessible via the server's filesystem.</span></p></blockquote> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.fseek.html">fseek</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.ftell.html">ftell</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>