array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.copy.php', 1 => 'copy', ), 'up' => array ( 0 => 'ref.filesystem.php', 1 => '文件系统函数', ), 'prev' => array ( 0 => 'function.clearstatcache.php', 1 => 'clearstatcache', ), 'next' => array ( 0 => 'function.delete.php', 1 => 'delete', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/filesystem/functions/copy.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
copy — 拷贝文件
from
源文件路径。
to
目标路径。如果 to
是一个 URL,则如果封装协议不支持覆盖已有的文件时拷贝操作会失败。
如果目标文件已存在,将会被覆盖。
context
A valid context resource created with stream_context_create().
示例 #1 copy() 例子
<?php
$file = 'example.txt';
$newfile = 'example.txt.bak';
if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
}
?>