<!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>Copies file</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.clearstatcache.html">clearstatcache</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.delete.html">delete</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.copy" class="refentry"> <div class="refnamediv"> <h1 class="refname">copy</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">copy</span> — <span class="dc-title">Copies file</span></p> </div> <div class="refsect1 description" id="refsect1-function.copy-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>copy</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$source</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$dest</code></span> [, <span class="methodparam"><span class="type">resource</span> <code class="parameter">$context</code></span> ] )</div> <p class="para rdfs-comment"> Makes a copy of the file <em><code class="parameter">source</code></em> to <em><code class="parameter">dest</code></em>. </p> <p class="para"> If you wish to move a file, use the <span class="function"><a href="function.rename.html" class="function">rename()</a></span> function. </p> </div> <div class="refsect1 parameters" id="refsect1-function.copy-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">source</code></em></span> <dd> <p class="para"> Path to the source file. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">dest</code></em></span> <dd> <p class="para"> The destination path. If <em><code class="parameter">dest</code></em> is a URL, the copy operation may fail if the wrapper does not support overwriting of existing files. </p> <div class="warning"><strong class="warning">Warning</strong> <p class="para"> If the destination file already exists, it will be overwritten. </p> </div> </dd> </dt> <dt> <span class="term"><em><code class="parameter">context</code></em></span> <dd> <p class="para"> A valid context resource created with <span class="function"><a href="function.stream-context-create.html" class="function">stream_context_create()</a></span>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.copy-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.copy-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.0</td> <td> Added context support. </td> </tr> <tr> <td>4.3.0</td> <td> Both <em><code class="parameter">source</code></em> and <em><code class="parameter">dest</code></em> may now be URLs if the "fopen wrappers" have been enabled. See <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span> for more details. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.copy-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2352"> <p><strong>Example #1 <span class="function"><strong>copy()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$file </span><span style="color: #007700">= </span><span style="color: #DD0000">'example.txt'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$newfile </span><span style="color: #007700">= </span><span style="color: #DD0000">'example.txt.bak'</span><span style="color: #007700">;<br /><br />if (!</span><span style="color: #0000BB">copy</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">, </span><span style="color: #0000BB">$newfile</span><span style="color: #007700">)) {<br /> echo </span><span style="color: #DD0000">"failed to copy </span><span style="color: #0000BB">$file</span><span style="color: #DD0000">...\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.copy-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <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> <li class="member"> <span class="function"><a href="function.rename.html" class="function" rel="rdfs-seeAlso">rename()</a> - Renames a file or directory</span></li> <li class="member">The section of the manual about <a href="features.file-upload.html" class="link">handling file uploads</a></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.clearstatcache.html">clearstatcache</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.delete.html">delete</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>