Home > Article > Backend Development > PHP implements batch modification of picture names
This article mainly shares with you the method of batch modifying image names in PHP, mainly in the form of code. I hope it can help everyone.
<?php // glob() 返回指定目录下的文件名以及目录 $arr = glob("img/*.jpg"); $time = time(); $i = 100001; // 循环遍历 foreach($arr as $file) { // 获取图片后缀名 $ext = pathinfo($file,PATHINFO_EXTENSION); // 确定图片的新名字 $name = $time.$i++ . "." . $ext; // 重命名 rename($file, $name); } die(); ?>
The above is the detailed content of PHP implements batch modification of picture names. For more information, please follow other related articles on the PHP Chinese website!