img文件夹里有1000张图片,如何将这一千张图片改名字为1到1000????
$arr = glob("img/*.jpg");
var_dump($arr);
$i = 1;
foreach($arr as $file) {
// 获取图片后缀名
$ext = pathinfo($file,PATHINFO_EXTENSION);
$name = $i++ . "." . $ext;
// 重命名
rename($file, $name);
}
解决了
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
可以用bash,假设你这php跑在linux下,有bash,可以做类似:
shell_exec("i=1;for file in /path/to/img; do mv $file $i; i=$i+1; done")当然php里其实有个函数叫rename: rename php manual,你可以:
注意下php版本就是了。
推薦你看下張鑫旭前不久寫的js一般般的網頁重構可以用js做什麼
上文就有用nodejs批量改名字