彻底解决Moodle上传文件中文文件名乱码解决方法

时间:2023-02-10 10:17:57
彻底解决Moodle上传文件中文文件名乱码解决方法 谢作如 [ 2008-5-21 8:19:00 ] 2推荐moodle对中文的支持不是很好,这是公认的BUG。在网上可以找到一些解决办法,其中最简单的做法是:-------------------------------config.php加入
$CFG->unicodecleanfilename = true;
===============================1.9试了下只要改这个就可以了
即可正常上传中文档名
------------------------------我在lib/moodlelib.php下也发现了这样一段说明,原来是官方的解决方案:/**
* Cleans a given filename by removing suspicious or troublesome characters
* Only these are allowed: alphanumeric _ - .
* Unicode characters can be enabled by setting $CFG->unicodecleanfilename = true in config.php
*
* WARNING: unicode characters may not be compatible with zip compression in backup/restore,
*          because native zip binaries do weird character conversions. Use PHP zipping instead.
*
* @param string $string  file name
* @return string cleaned file name
*/

    其实这样并不是很彻底的方案。如果在插入超链接时选择本站文件,返回的文件目录中中文文件名还是乱码的。不过我发现只要在浏览器中选择utf-8编码,还是可以正确浏览的,但这样毕竟不方便。
     再也找不到相关的资料了,于是自力更生,我找了点PHP的资料,直接修改了coursefiles.php文件(lib/editor/htmlarea/coursefiles.php),在第二行加上这样一句:@header("Content-Type: text/html; charset=utf-8");再次测试网页,发现浏览器就可以自动选择utf-8编码,不再出现乱码了。     终于算彻底解决中文文件名乱码的问题。