WordPress 上传文件名自动修改为MD5 - 蔚藍部落

WordPress 上传文件名自动修改为MD5

在主题的functions.php添加如下内容

function rename_filename($filename) {
    $info = pathinfo($filename);
    $ext = empty($info['extension']) ? '' : '.' . $info['extension'];
    $name = basename($filename, $ext);
    return substr(md5($name), 0, 16) . $ext; //截取前面16个字符
}
add_filter('sanitize_file_name', 'rename_filename', 10);

来源:http://www.ixiqin.com/?p=90

发表新评论
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif