WordPress 中文图片 上传 自动重命名

WordPress 中文图片 上传 自动重命名

由于国人很少有在上传图片前将图片名重命名为英语的,所以自动重命名对于WP来说尤为重要,特别是LINUX的不支持中文名的。

WordPress上传多媒体的代码都存放于\wp-admin\includes\里面的file.php,打开这个文件,filename=wpuniquefilename(uploads['path'], file[name],unique_filename_callback );// Move the file to the uploads dir,在此句$filename赋值前添加代码如下:

$time=date("YmdHis");$type_change = array('image'=>'.');$file_type = strtr($file['type'],$type_change);
$file['name'] = $time."".mt_rand(1,100)."".$file_type ;

之后代码如下:

    $time=date("YmdHis");$type_change = array('image'=>'.');$file_type = strtr($file['type'],$type_change);
$file['name'] = $time.''.mt_rand(1,100).''.$file_type ; $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); // Move the file to the uploads dir

保存下,上传多媒体后文件就自动重命名为2014012315450088格式,年份月份日期时间和随机数字。

posted @ 2014-11-22 23:30  yueke  阅读(300)  评论(0编辑  收藏  举报