<!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>Determine accessibility of a file</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.posix.html">POSIX Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.posix-ctermid.html">posix_ctermid</a></div> <div class="up"><a href="ref.posix.html">POSIX Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.posix-access" class="refentry"> <div class="refnamediv"> <h1 class="refname">posix_access</h1> <p class="verinfo">(PHP 5 >= 5.1.0)</p><p class="refpurpose"><span class="refname">posix_access</span> — <span class="dc-title"> Determine accessibility of a file </span></p> </div> <div class="refsect1 description" id="refsect1-function.posix-access-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>posix_access</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$file</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code><span class="initializer"> = POSIX_F_OK</span></span> ] )</div> <p class="para rdfs-comment"> <span class="function"><strong>posix_access()</strong></span> checks the user's permission of a file. </p> </div> <div class="refsect1 parameters" id="refsect1-function.posix-access-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">file</code></em></span> <dd> <p class="para"> The name of the file to be tested. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">mode</code></em></span> <dd> <p class="para"> A mask consisting of one or more of <strong><code>POSIX_F_OK</code></strong>, <strong><code>POSIX_R_OK</code></strong>, <strong><code>POSIX_W_OK</code></strong> and <strong><code>POSIX_X_OK</code></strong>. </p> <p class="para"> <strong><code>POSIX_R_OK</code></strong>, <strong><code>POSIX_W_OK</code></strong> and <strong><code>POSIX_X_OK</code></strong> request checking whether the file exists and has read, write and execute permissions, respectively. <strong><code>POSIX_F_OK</code></strong> just requests checking for the existence of the file. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.posix-access-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-function.posix-access-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-3648"> <p><strong>Example #1 <span class="function"><strong>posix_access()</strong></span> example</strong></p> <div class="example-contents"><p> This example will check if the $file is readable and writable, otherwise will print an error message. </p></div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br />$file </span><span style="color: #007700">= </span><span style="color: #DD0000">'some_file'</span><span style="color: #007700">;<br /><br />if (</span><span style="color: #0000BB">posix_access</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">, </span><span style="color: #0000BB">POSIX_R_OK </span><span style="color: #007700">| </span><span style="color: #0000BB">POSIX_W_OK</span><span style="color: #007700">)) {<br /> echo </span><span style="color: #DD0000">'The file is readable and writable!'</span><span style="color: #007700">;<br /><br />} else {<br /> </span><span style="color: #0000BB">$error </span><span style="color: #007700">= </span><span style="color: #0000BB">posix_get_last_error</span><span style="color: #007700">();<br /><br /> echo </span><span style="color: #DD0000">"Error </span><span style="color: #0000BB">$error</span><span style="color: #DD0000">: " </span><span style="color: #007700">. </span><span style="color: #0000BB">posix_strerror</span><span style="color: #007700">(</span><span style="color: #0000BB">$error</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.posix-access-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">When <a href="features.safe-mode.html" class="link">safe mode</a> is enabled, PHP checks whether the files or directories being operated upon have the same UID (owner) as the script that is being executed.</span></p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-function.posix-access-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.posix-get-last-error.html" class="function" rel="rdfs-seeAlso">posix_get_last_error()</a> - Retrieve the error number set by the last posix function that failed</span></li> <li class="member"> <span class="function"><a href="function.posix-strerror.html" class="function" rel="rdfs-seeAlso">posix_strerror()</a> - Retrieve the system error message associated with the given errno</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="ref.posix.html">POSIX Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.posix-ctermid.html">posix_ctermid</a></div> <div class="up"><a href="ref.posix.html">POSIX Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>