moodle1.8.2上傳中文檔名的檔案
前幾天才剛將moodle升級到1.8.2,剛剛突然想到中文檔名的問題,剛剛試著上傳中文檔名的檔案,果然檔案上傳後,中文又不見了。
所以根據之前的文章「 修正moodle上傳中文檔案問題」,想說再改一次吧!改好了,又恢復可以上傳中文檔名了。不過,改法有些不同,簡單一些了。
一、修改config.php
根據之前的文章,原本要改 /lib/moodlelib.php 這檔案,將這兩行 「$string = convert_high...」、「string = preg_replace(...」給註解掉。
不過,剛剛去找,卻找不到,程式已有些不同。還好看到那「function clean_filename($string) 」上面有說明:
/**
* 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
*/
function clean_filename($string) {
global $CFG;
if (empty($CFG->unicodecleanfilename)) {
$textlib = textlib_get_instance();
$string = $textlib->specialtoascii($string);
$string = preg_replace('/[^\.a-zA-Z\d\_-]/','_', $string ); // only allowed chars
所以再去看看config.php,找到了下面這一段,將下面紅色字那一行前面的註解 // 給拿掉
// Allow unicode characters in uploaded files, generated reports, etc.
// This setting is new and not much tested, there are known problems
// with backup/restore that will not be solved, because native infozip
// binaries are doing some weird conversions - use internal PHP zipping instead.
// NOT RECOMMENDED FOR PRODUCTION SITES
$CFG->unicodecleanfilename = true;
這樣就可以上傳中文檔名了。但在下載中文檔名檔案時,還是一樣跟「 修正moodle上傳中文檔案問題」裡說到的在IE下,中文檔名的檔案還是會變成隨機英文字串的檔名,所以再繼續修改吧!
二、修改 /moodle/file.php
約在第174行(倒數第9行) ,將底下紅色字那一行註解掉,這樣就可以了。
// ========================================
// finally send the file
// ========================================
session_write_close(); // unlock session during fileserving
// $filename = $args[count($args)-1];
send_file($pathname, $filename, $lifetime, $CFG->filteruploadedfiles, false, $forcedownload);
function not_found($courseid) {
global $CFG;
header('HTTP/1.0 404 not found');
error(get_string('filenotfound', 'error'), $CFG->wwwroot.'/course/view.php?id='.$courseid); //this is not displayed on IIS??
}
?>
PS:我不確定這樣的改法,會不會造成其他影響,不過至少可以在moodle上正常上傳、下載中文檔名的檔案。





24/01/2008, 23:14
JYCoffee:
我猜你安裝的版本應該是1.8.4吧!而且應該是在Windows下架設moodle吧!
若是在Windows下安裝,由於目錄權限問題,config.php會自動寫入、產生,linux系統大概要自己寫入。
至於這一行「$CFG->unicodecleanfilename = true;」可以在config-dist.php這檔案的約172行看到。
最近學校moodle剛更新到1.8.4,也有位朋友問這問題(看一下迴響的部份),我自己測試的結果,在Windows下安裝moodle1.8.4,若在config.php加上上面那一段,某些中文檔案可以上傳成功,某些就又不行,可能要再多測試、找問題了。
或者你可以到「moodle中文加油站」問問,那裡比較多高手。
24/01/2008, 11:45
沒看到moodle\config.php 您所提的內容耶, 若自己加上$CFG->unicodecleanfilename = true; 連檔案都傳不上去, 我有改錯檔案嗎?
Joann
03/10/2007, 23:39
To現在正在為moodle煩腦的人 :
兩套moodle,存放的目錄取不同的名稱,資料庫也用不同的名稱,不就好了嗎?
這事我有做過,之前學校同事也需要架套moodle,所以我在同一台主機就放兩套moodle
http://163.17.156.130/moodle/
http://163.17.156.130/moodle_andy/
不知道有沒有誤解你的意思!
03/10/2007, 20:53
嗨!看你的部落格想必你應該對moodle有一番了解吧
可以問你幾個問題嗎!拜託……就是老師要我們在同一台電腦用兩個moodle
試了好多遍都沒有辦法!不知道大大您知道這個問題要怎麼解決嗎!?謝謝