<!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>Change directory</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.dir.html">Directory Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.chroot.html">chroot</a></div> <div class="up"><a href="ref.dir.html">Directory Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.chdir" class="refentry"> <div class="refnamediv"> <h1 class="refname">chdir</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">chdir</span> — <span class="dc-title">Change directory</span></p> </div> <div class="refsect1 description" id="refsect1-function.chdir-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>chdir</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$directory</code></span> )</div> <p class="para rdfs-comment"> Changes PHP's current directory to <em><code class="parameter">directory</code></em>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.chdir-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">directory</code></em></span> <dd> <p class="para"> The new current directory </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.chdir-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 errors" id="refsect1-function.chdir-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> Throws an error of level <strong><code>E_WARNING</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-function.chdir-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2333"> <p><strong>Example #1 <span class="function"><strong>chdir()</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">// current directory<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">getcwd</span><span style="color: #007700">() . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">chdir</span><span style="color: #007700">(</span><span style="color: #DD0000">'public_html'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// current directory<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">getcwd</span><span style="color: #007700">() . </span><span style="color: #DD0000">"\n"</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> /home/vincent /home/vincent/public_html </pre></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.chdir-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 directory in which the script is operating has the same UID (owner) as the script that is being executed.</span></p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-function.chdir-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.getcwd.html" class="function" rel="rdfs-seeAlso">getcwd()</a> - Gets the current working directory</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.dir.html">Directory Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.chroot.html">chroot</a></div> <div class="up"><a href="ref.dir.html">Directory Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>