ucms批量修改图片及文件名称

13 / Jan / 2022 PM Note 14

ucms批量修改图片及文件名称方法:通过内置函数rename()批量建站的时候需要修改文件名字 以及 打乱模板class id等,前面介绍了怎么打乱模板class id伪原创,现在说说批量修改static静态文件名称方法。

ucms多站点批量修改static静态文件名称

代码:

<?php

/**
 * @Author: TIM
 * @Date:   2022-01-12 14:31:12
 * @Email:  61468384@qq.com
 * @Blog:   http://www.tim-blog.com
 * @Desc:   简单即是美 Simple is beautiful...
 * @Last Modified by:   1
 * @Last Modified time: 2022-01-13 18:17:18
 */


//随机数
function randchar($length, $type) {
    $arr = array(1 => "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    if($type == 0) {
        array_pop($arr);
        $string = implode("", $arr);
    } elseif($type == "-1") {
        $string = implode("", $arr);
    } else {
        $string = $arr[$type];
    }
    $count = strlen($string) - 1;
    for ($i = 0; $i < $length; $i++) {
        $str[$i] = $string[rand(0, $count)];
        @$code .= $str[$i];
    }
    return $code;
}
//项目案例
function works() {
    $arr = glob("insommnia/works/*");
    foreach($arr as $file) {
        $ext = pathinfo($file,PATHINFO_EXTENSION);
        $name = md5(randchar(20,1)) . "." . $ext;
        rename($file,'insommnia/works/'.$name);
        //die();
    }
}
echo works();
echo "works修改成功";
//首页banner
function banner() {
    $arr = glob("insommnia/banner/*");
    foreach($arr as $file) {
        $ext = pathinfo($file,PATHINFO_EXTENSION);
        $name = md5(randchar(20,1)) . "." . $ext;
        rename($file,'insommnia/banner/'.$name);
        //die();
    }
}
echo banner();
echo "banner修改成功";
//contact
function contact() {
    $arr = glob("insommnia/contact/*");
    foreach($arr as $file) {
        $ext = pathinfo($file,PATHINFO_EXTENSION);
        $name = md5(randchar(20,1)) . "." . $ext;
        rename($file,'insommnia/contact/'.$name);
        //die();
    }
}
echo contact();
echo "contact修改成功";
//renwu
function renwu() {
    $arr = glob("insommnia/renwu/*");
    foreach($arr as $file) {
        $ext = pathinfo($file,PATHINFO_EXTENSION);
        $name = md5(randchar(20,1)) . "." . $ext;
        rename($file,'insommnia/renwu/'.$name);
        //die();
    }
}
echo renwu();
echo "renwu修改成功";

说明:文件目录自行对比个人站点,$name为数字小写/大写字母随机抽取20个单位的md5加密,是否需要加密自行修改!

发布评论