<!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>Renames a file or directory</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.realpath.html">realpath</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.rewind.html">rewind</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.rename" class="refentry"> <div class="refnamediv"> <h1 class="refname">rename</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">rename</span> — <span class="dc-title">Renames a file or directory</span></p> </div> <div class="refsect1 description" id="refsect1-function.rename-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>rename</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$oldname</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$newname</code></span> [, <span class="methodparam"><span class="type">resource</span> <code class="parameter">$context</code></span> ] )</div> <p class="para rdfs-comment"> Attempts to rename <em><code class="parameter">oldname</code></em> to <em><code class="parameter">newname</code></em>, moving it between directories if necessary. If <em><code class="parameter">newname</code></em> exists, it will be overwritten. </p> </div> <div class="refsect1 parameters" id="refsect1-function.rename-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">oldname</code></em></span> <dd> <p class="para"> </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> The old name. The wrapper used in <em><code class="parameter">oldname</code></em> <em class="emphasis">must</em> match the wrapper used in <em><code class="parameter">newname</code></em>. </p> </p></blockquote> </dd> </dt> <dt> <span class="term"><em><code class="parameter">newname</code></em></span> <dd> <p class="para"> The new name. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">context</code></em></span> <dd> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">Context support was added with PHP 5.0.0. For a description of <em>contexts</em>, refer to <a href="book.stream.html" class="xref">Streams</a>.</span></p></blockquote> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.rename-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 changelog" id="refsect1-function.rename-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>5.3.1</td> <td> <span class="function"><strong>rename()</strong></span> can now rename files across drives in Windows. </td> </tr> <tr> <td>5.0.0</td> <td> <span class="function"><strong>rename()</strong></span> can now also be used with <em class="emphasis">some</em> URL wrappers. Refer to <a href="wrappers.html" class="xref">Supported Protocols and Wrappers</a> for a listing of which wrappers support <span class="function"><strong>rename()</strong></span>. </td> </tr> <tr> <td>4.3.3</td> <td> <span class="function"><strong>rename()</strong></span> may now be able to rename files across partitions on *nix based systems, provided the appropriate permissions are held. Warnings may be generated if the destination filesystem doesn't permit <em>chown()</em> or <em>chmod()</em> system calls to be made on files — for example, if the destination filesystem is a FAT filesystem. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.rename-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2428"> <p><strong>Example #1 Example with <span class="function"><strong>rename()</strong></span></strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />rename</span><span style="color: #007700">(</span><span style="color: #DD0000">"/tmp/tmp_file.txt"</span><span style="color: #007700">, </span><span style="color: #DD0000">"/home/user/login/docs/my_file.txt"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.rename-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.copy.html" class="function" rel="rdfs-seeAlso">copy()</a> - Copies file</span></li> <li class="member"> <span class="function"><a href="function.unlink.html" class="function" rel="rdfs-seeAlso">unlink()</a> - Deletes a file</span></li> <li class="member"> <span class="function"><a href="function.move-uploaded-file.html" class="function" rel="rdfs-seeAlso">move_uploaded_file()</a> - Moves an uploaded file to a new location</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.realpath.html">realpath</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.rewind.html">rewind</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>