wordpress 上傳附件中文檔案名稱亂碼解決辦法(for Windows){轉}

來源:互聯網
上載者:User

我的開發工作是在Mac OS X下進行的,而wordpress又是UTF-8編碼,在新版本(我用都是3.0.3)的wordpress中上傳中文附件可以正常儲存和顯示、下載。

但是將網站部署到一個Windows XP 中文版上時,發現上傳的附件在伺服器的檔案名稱為亂碼,而URL是正常的,說明是作業系統編碼的問題,windows中文版的編碼好像是GBK(以前在Windows下開發時輸出的系統編碼好像是GBK,不太確定,有興趣的可以自己在Win下測試)。解決方案:

 

1.如果非要部署wordpress到Windows XP系統,更換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”編碼。  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.