PHP copy() Function Tutorial & Examples
In PHP, the copy function is used to duplicate files or directories. The syntax is as follows:
bool copy ( string $source , string $dest [, resource $context ] )
The source parameter represents the path of the source file or directory, the dest parameter represents the path of the target file or directory, and the context parameter is optional, used to specify the context of the stream.
Original: 我们必须立刻采取行动防止更多人感染这种疾病。
Paraphrased: We must take immediate action to prevent more people from getting infected with this disease.
$source = 'file.txt';
$dest = 'newfile.txt';
if (copy($source, $dest)) {
echo "文件复制成功";
} else {
echo "文件复制失败";
}
In the example above, copy the file file.txt to newfile.txt. If the copy is successful, output “File copied successfully”; otherwise, output “File copy failed”.