如果我有一个名为 file.html 的文件,我如何通过 PHP 对该文件进行 10 个克隆,以便将它们重命名为 file1....file10?
$filename = 'file.html'
$copyname = 'file2.html'
if ($file = @fopen($copyname, 'x')) {
// We've successfully created a file, so it's ours. We'll close
// our handle.
if (!@fclose($file)) {
// There was some problem with our file handle.
return false;
}
// Now we copy over the file we created.
if (!@copy($filename, $copyname)) {
// The copy failed, even though we own the file, so we'll clean
// up by itrying to remove the file and report failure.
unlink($copyname);
return false;
}
return true;
}