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

PHP implements batch modification of picture names

小云云
Release: 2023-03-22 14:40:01
Original
2063 people have browsed it

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();
?>
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template