批量将任何文件复制搭配任意目录
使用命令行或脚本可以实现批量复制任意文件到指定目录,支持多文件、多目录操作,适合文件整理、备份和自动化任务

本脚本采用php
代码:
<?php
// 定义源图片 URL
$image_url = "https://www.xxx.xx/img/xx.png";
// 读取 batch_sites.txt 文件
$file = fopen("batch_sites.txt", "r") or die("无法打开文件!");
// 逐行读取文件内容
while (!feof($file)) {
// 读取一行内容并去除首尾空白
$line = trim(fgets($file));
// 如果行内容不为空,则进行处理
if (!empty($line)) {
// 设置目标目录
$target_dir = $line;
$target_file = $target_dir . basename($image_url);
// 检查目标目录是否存在,不存在则创建
if (!file_exists($target_dir)) {
mkdir($target_dir, 0755, true);
}
// 使用 curl 下载图片
$ch = curl_init($image_url);
$fp = fopen($target_file, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
if (!curl_exec($ch)) {
echo "下载失败: " . curl_error($ch) . " -> $target_dir\n";
} else {
echo "图片已成功下载到 $target_file\n";
}
curl_close($ch);
fclose($fp);
}
}
// 关闭 batch_sites.txt 文件
fclose($file);
?>
batch_sites.txt填写要复制到的路径一行一个
/www/wwwroot/1.com
/www/wwwroot/2.com
/www/wwwroot/3.com
分享
你的反应是什么?






