【谐态】…………………………………………………………………………………………>>> |
|
网站中使用php批量强制拷贝覆盖文件 |
|
php 批量强制拷贝覆盖文件
可以使用PHP的copy()函数来进行批量强制拷贝并覆盖文件。
代码如下:
//*************************
<?php
$sourceDir = ’/path/to/source’ //源目录路径
$destinationDir = ’/path/to/destination’ //目标目录路径
//获取源目录下所有文件及子目录中的文件
function getAllFiles($dir) {
$files = []
foreach (scandir($dir) as $file) {
if ($file == ’.’ || $file == ’..’) continue
$currentPath = "$dir/$file"
if (is_dir($currentPath)) {
$files = array_merge($files, getAllFiles($currentPath))
} else {
$files[] = $currentPath
}
}
return $files
}
//遍历源目录下的每个文件,将其复制到目标目录
foreach(getAllFiles($sourceDir) as $file){
copy($file, str_replace($sourceDir, $destinationDir, $file), true)
}
?>
//*************************
上面的代码会将指定源目录($sourceDir)下的所有文件及子目录中的文件都复制到目标目录($destinationDir)中,如果存在同名文件则会被覆盖。 |
发布时间:2024/1/23
阅读:1216次 来源:烟台数据安全处理中心 |
|
|
|
|