uTools-Manuals/docs/php/copy.html
2019-04-28 19:00:34 +08:00

158 lines
5.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>拷贝文件</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.copy" class="refentry">
<div class="refnamediv">
<h1 class="refname">copy</h1>
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">copy</span> &mdash; <span class="dc-title">拷贝文件</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.copy-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<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>
] ) : <span class="type">bool</span></div>
<p class="para rdfs-comment">
将文件从 <code class="parameter">source</code> 拷贝到 <code class="parameter">dest</code>
</p>
<p class="para">
如果要移动文件的话,请使用 <span class="function"><a href="rename.html" class="function">rename()</a></span> 函数。
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.copy-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">source</code></dt>
<dd>
<p class="para">
源文件路径。
</p>
</dd>
<dt>
<code class="parameter">dest</code></dt>
<dd>
<p class="para">
目标路径。如果 <code class="parameter">dest</code> 是一个 URL则如果封装协议不支持覆盖已有的文件时拷贝操作会失败。
</p>
<div class="warning"><strong class="warning">Warning</strong>
<p class="para">
如果目标文件已存在,将会被覆盖。
</p>
</div>
</dd>
<dt>
<code class="parameter">context</code></dt>
<dd>
<p class="para">
A valid context resource created with
<span class="function"><a href="stream_context_create.html" class="function">stream_context_create()</a></span>.
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.copy-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
成功时返回 <strong><code>TRUE</code></strong> 或者在失败时返回 <strong><code>FALSE</code></strong>
</p>
</div>
<div class="refsect1 changelog" id="refsect1-function.copy-changelog">
<h3 class="title">更新日志</h3>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>5.3.0</td>
<td>
增加了对 context 的支持。
</td>
</tr>
<tr>
<td>4.3.0</td>
<td>
如果启用了“fopen wrappers”的话<code class="parameter">source</code>
<code class="parameter">dest</code> 都可以是 URL。更多细节见 <span class="function"><a href="fopen.html" class="function">fopen()</a></span>
</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.copy-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-2765">
<p><strong>Example #1 <span class="function"><strong>copy()</strong></span> 例子</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'example.txt'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$newfile&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'example.txt.bak'</span><span style="color: #007700">;<br /><br />if&nbsp;(!</span><span style="color: #0000BB">copy</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$newfile</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"failed&nbsp;to&nbsp;copy&nbsp;</span><span style="color: #0000BB">$file</span><span style="color: #DD0000">...\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.copy-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="move_uploaded_file.html" class="function" rel="rdfs-seeAlso">move_uploaded_file()</a> - 将上传的文件移动到新位置</span></li>
<li class="member"><span class="function"><a href="rename.html" class="function" rel="rdfs-seeAlso">rename()</a> - 重命名一个文件或目录</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></div></div></body></html>