今日需要在 Server 2003 的 IIS 下部署一个 wordpress 网站,发现上传中文文件名的文件时保存下来的文件乱码,修改 wordpress 核心里的代码可以解决问题,不过这样就不能随意升级 wordpress 本身了。

修改 wp-admin/includes/file.php

1
2
function wp_handle_upload( &$file, $overrides = false, $time = null ) {
//$new_file = $uploads['path'] . "/$filename";

找到上面的代码,替换成下面的。

1
$new_file = $uploads['path'] . "/" . iconv("UTF-8","GB2312",$filename);
1
return apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'upload' );

找到上面的代码,替换成下面的。

1
return apply_filters( 'wp_handle_upload', array( 'file' => $uploads['path'] . "/$filename", 'url' => $url, 'type' => $type ) , 'upload');