PHP 中的 copy() 函数
phpprogrammingserver side programming更新于 2025/10/6 13:14:00
copy() 函数复制文件。将创建源文件到目标文件的副本。如果目标文件已经存在,则会被覆盖。
语法
copy(source_file, dest_file)
参数
source_file − 设置要复制的文件
dest_file − 设置要复制到的文件
返回
copy() 函数返回。
- 成功时为 TRUE
- 失败时为 FALSE
示例
<?php
echo copy("D:/myfiles/sourcefile.dat","D:/myfiles/destfile.dat");
?>
输出
true
现在让我们看另一个例子。
示例
<?php
$file = '/usr/home/guest/example.txt';
$newfile = '/usr/home/guest/example.txt.bak';
if (!copy($file, $newfile)) {
echo "failed to copy $file...
";
} else {
echo "copied $file into $newfile
";
}
?>
输出
failed to copy /usr/home/guest/example.txt...

