让wordpress上传支持中文文件名

中文文件名的文件在上传后,移动到对应文件夹会报错,可以修改/wp-admin/includes/file.php文件,修改以下两处即可,在wordpress3.2下测试通过。

function wp_handle_upload( &$file, $overrides = false, $time = null ) {
//….
// Move the file to the uploads dir
//$new_file = $uploads['path'] . “/$filename”;
// 修正中文文件名编码问题
$new_file = $uploads['path'] . “/” . iconv(“UTF-8″,”GB2312″,$filename);
//…
//return apply_filters( ‘wp_handle_upload’, array( ‘file’ => $new_file, ‘url’ => $url, ‘type’ => $type ), ‘upload’ );
// 修正中文文件名编码问题
return apply_filters( ‘wp_handle_upload’, array( ‘file’ => $uploads['path'] . “/$filename”, ‘url’ => $url, ‘type’ => $type ) , ‘upload’);
}

注:其中的 iconv(“UTF-8″,”GB2312″,$filename);  也可以使用“GBK”编码


你可能感兴趣的:(function,wordpress,upload,File,url,Path)