Home  >  Article  >  Backend Development  >  PHP implements batch modification of picture names

PHP implements batch modification of picture names

小云云
小云云Original
2018-03-28 14:09:562048browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn