WordPress uploads attachments with garbled Chinese file names (for Windows)

Source: Internet
Author: User

My development work is in Mac OS x, and WordPress is UTF-8 code, in the new version (I use all 3.0.3) you can store, display, and download Chinese attachments in WordPress.

However, when you deploy the website on a Windows XP Chinese version, you will find that the uploaded attachments are garbled in the server file name, while the URL is normal, which indicates that it is a problem of operating system encoding, the Windows Chinese Version code seems to be GBK (the system code output during development in Windows previously seems to be GBK. If you are interested, you can test it in Windows ). Solution:

 

1. If you have to deploy WordPress on Windows XP, replace the Windows XP English version.

2. To deploy Wordpress to the Chinese version of Windows XP, modify the following code:

// WP-admin/shortdes/file. php. Take 3.0.3 as an example:

 Function wp_handle_upload (& $ file, $ overrides = false, $ time = NULL ){
//....
// Move the file to the uploads dir
// $ New_file = $ uploads ['path']. "/$ FILENAME ";
// Fixed the problem of Chinese file name encoding.
$ New_file = $ uploads ['path']. "/". iconv ("UTF-8", "gb2312", $ filename );

//...

// Return apply_filters ('wp _ handle_upload ', array ('file' => $ new_file, 'url' => $ URL, 'type' => $ type ), 'upload ');
// Fixed the problem of Chinese file name encoding.
Return apply_filters ('wp _ handle_upload ', array ('file' => $ uploads ['path']. "/$ FILENAME", 'url' => $ URL, 'type' => $ type), 'upload ');

The iconv ("UTF-8", "gb2312", $ filename); can also be encoded using GBK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.