在PHP中,我们可以使用copy
函数来复制一个文件。该函数需要两个参数:源文件路径和目标文件路径。
$source_file = "example.txt";
$destination_file = "example_copy.txt";
if(!copy($source_file, $destination_file)) {
echo "复制文件失败。";
} else {
echo "文件成功复制。";
}
如果我们想要移动一个文件,我们可以使用rename
函数。该函数需要两个参数:源文件路径和目标文件路径。
$source_file = "example.txt";
$destination_file = "example_folder/example.txt";
if(!rename($source_file, $destination_file)) {
echo "移动文件失败。";
} else {
echo "文件成功移动。";
}
在此示例中,我们将example.txt
文件从当前目录移动到example_folder
文件夹中。