WordPress:上传图片不正常显示
在wordpress的使用过程中,你可能会遇到如题所示的问题。
它的具体呈现如下图所示:
它之所以显示不正常的原因是因为中文上传服务器后乱码,故而无法找到确切的文件了:
在Wordpress中,控制文件上传的方法位于:$WORDPRESS_HOME\wp-admin\includes\file.php
将其中如下的代码修改:
原代码:
1 2 |
// Move the file to the uploads dir. $new_file = $uploads['path'] . "/$filename"; |
1 2 3 |
// Move the file to the uploads dir. /* $new_file = $uploads['path'] . "/$filename"; */ $new_file = $uploads['path'] . "/".date("YmdHis").floor(microtime()*1000).".".$ext; |
看看在后台服务器中的呈现:
可以看到,中文的文件名被随机的重命名为了数字的文件名,从而避免了乱码的问题。
————————————————————
Done。