<?php
$format = 'jpg';
$path = './';
$files = getfile($path, $format);
$i = 1;
foreach ($files as $v) {
    $tv = basename($v);
    list($name, $ext) = explode('.', $tv);
    $newname = $path . $i . '.' . $ext;
    if (rename($v, $newname)) {
        echo '成功将' . $v . '重命名' . $newname . '';
    }
    $i++;
}
function getfile($path, $format) {
    $dirs = array();
    foreach (glob("$path*") as $d) {
        $tmp = explode('.', $d);
        $k = end($tmp);
        if (is_file($d) && ($k == strtolower($format))) {
            $dirs[] = $d;
        }
    }
    return $dirs;
}
Last modification:May 28, 2022
如果觉得我的文章对你有用,请随意赞赏