这段函数很好的解决了一些主机不支持中文文件名的弊端。判断是不是中文如果是中文,则重命名为MD5值。
使用时直接把以下代码放到fuctions.php中即可
<code>
function upload_file($filename) {
$parts = explode('.', $filename);
$filename = array_shift($parts);
$extension = array_pop($parts);
foreach ( (array) $parts as $part)
$filename .= '.' . $part;
if(preg_match('/[一-龥]/u', $filename)){
$filename = md5($filename);
}
$filename .= '.' . $extension;
return $filename ;
}
add_filter('sanitize_file_name', 'upload_file', 5,1);
</code>
function upload_file($filename) {
$parts = explode('.', $filename);
$filename = array_shift($parts);
$extension = array_pop($parts);
foreach ( (array) $parts as $part)
$filename .= '.' . $part;
if(preg_match('/[一-龥]/u', $filename)){
$filename = md5($filename);
}
$filename .= '.' . $extension;
return $filename ;
}
add_filter('sanitize_file_name', 'upload_file', 5,1);
</code>