但是將站點部署到一個Windows XP 中文版上時,發(fā)現(xiàn)上傳的附件在服務(wù)器的文件名為亂碼,而URL是正常的,說明是操作系統(tǒng)編碼的問題,windows中文版的編碼好像是GBK(以前在Windows下開發(fā)時輸出的系統(tǒng)編碼好像是GBK,不太確定,有興趣的可以自己在Win下測試)。解決方案:
1.如果非要部署wordpress到Windows XP系統(tǒng),更換Windows XP English version
2.如果非要部署wordpress到Windows XP 中文版,修改以下代碼:
//wp-admin/includes/file.php,以3.0.3為例:
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”編碼。