📄 function.copy.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Copies file</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div 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"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><b>copy</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$source</tt></span> , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$dest</tt></span> [, <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$context</tt></span> ] )</div> <p class="para rdfs-comment"> Makes a copy of the file <i><tt class="parameter">source</tt></i> to <i><tt class="parameter">dest</tt></i>. </p> <p class="para"> If you wish to move a file, use the <a href="function.rename.html" class="function">rename()</a> function. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">source</tt></i></span> <dd> <p class="para"> Path to the source file. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">dest</tt></i></span> <dd> <p class="para"> The destination path. If <i><tt class="parameter">dest</tt></i> is a URL, the copy operation may fail if the wrapper does not support overwriting of existing files. </p> <div class="warning"><b class="warning">Warning</b> <p class="para"> If the destination file already exists, it will be overwritten. </p> </div> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">context</tt></i></span> <dd> <p class="para"> A valid context resource created with <a href="function.stream-context-create.html" class="function">stream_context_create()</a>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <b><tt>TRUE</tt></b> on success or <b><tt>FALSE</tt></b> on failure. </p> </div> <div class="refsect1 changelog"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">5.3.0</td> <td colspan="1" rowspan="1" align="left"> Added context support. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">4.3.0</td> <td colspan="1" rowspan="1" align="left"> Both <i><tt class="parameter">source</tt></i> and <i><tt class="parameter">dest</tt></i> may now be URLs if the "fopen wrappers" have been enabled. See <a href="function.fopen.html" class="function">fopen()</a> for more details. </td> </tr> </tbody> </colgroup> </table> </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>copy()</b> example</b></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 $file...\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"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.move-uploaded-file.html" class="function" rel="rdfs-seeAlso">move_uploaded_file()</a></li> <li class="member"><a href="function.rename.html" class="function" rel="rdfs-seeAlso">rename()</a></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 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -