wordpress 上传附件中文文件名乱码解决办法(for Windows)


本文整理自网络,侵删。

但是将站点部署到一个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”编码。

标签:WordPress

相关阅读 >>

wordpress上传图片自动重命名的方法

vps中使用lnmp安装wordpress教程

整理的一些实用wordpress后台mysql操作命令

解决更新wordpress3.7后db-cache缓冲插件冲突问题

再谈php未来之路

wordpress在iis下伪静态后子目录无法访问的解决方法

wordpress插件开发设计

wordpress 实现文章评论排行榜

wordpress中加入google搜索功能的简单步骤讲解

wordpress插件的使用

更多相关阅读请进入《wordpress》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...