<!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>Changes file owner</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.chmod.html">chmod</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.clearstatcache.html">clearstatcache</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.chown" class="refentry"> <div class="refnamediv"> <h1 class="refname">chown</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">chown</span> — <span class="dc-title">Changes file owner</span></p> </div> <div class="refsect1 description" id="refsect1-function.chown-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>chown</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span> , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$user</code></span> )</div> <p class="para rdfs-comment"> Attempts to change the owner of the file <em><code class="parameter">filename</code></em> to user <em><code class="parameter">user</code></em>. Only the superuser may change the owner of a file. </p> </div> <div class="refsect1 parameters" id="refsect1-function.chown-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> <dt> <span class="term"><em><code class="parameter">user</code></em></span> <dd> <p class="para"> A user name or number. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.chown-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.chown-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2350"> <p><strong>Example #1 Simple <span class="function"><strong>chown()</strong></span> usage</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">// File name and username to use<br /></span><span style="color: #0000BB">$file_name</span><span style="color: #007700">= </span><span style="color: #DD0000">"foo.php"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$path </span><span style="color: #007700">= </span><span style="color: #DD0000">"/home/sites/php.net/public_html/sandbox/" </span><span style="color: #007700">. </span><span style="color: #0000BB">$file_name </span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$user_name </span><span style="color: #007700">= </span><span style="color: #DD0000">"root"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Set the user<br /></span><span style="color: #0000BB">chown</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">, </span><span style="color: #0000BB">$user_name</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Check the result<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: #0000BB">$path</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">posix_getpwuid</span><span style="color: #007700">(</span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #DD0000">'uid'</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 ( [name] => root [passwd] => x [uid] => 0 [gid] => 0 [gecos] => root [dir] => /root [shell] => /bin/bash ) </pre></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.chown-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> <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.chown-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.chmod.html" class="function" rel="rdfs-seeAlso">chmod()</a> - Changes file mode</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.chmod.html">chmod</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.clearstatcache.html">clearstatcache</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>