多言語対応:ファイルのダウンロード
提供:MoodleDocs
ファイルをダウンロードするとファイル名が文字化けする
実際にはIE固有の問題です.クライアントPCとして日本語WidnowsPCが多く用いられるため,インストール後の早い段階で問題になります.コースファイルやフォーラムの添付ファイルなどをダウンロードするために日本語を含むファイル名をクリックしてクライアントPCへにダウンロードすると,ファイル名が化ける場合があります.
この障害はlib/filelib.php中のsend_file()内の以下の箇所を赤い文字で示したように修正することで解決します.本家Moodle1.8.3+でも対策が講じられましたが不十分です.
//IE compatibiltiy HACK! if (ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } //try to disable automatic sid rewrite in cookieless mode @ini_set("session.use_trans_sid", "false"); //do not put '@' before the next header to detect incorrect moodle configurations, //error should be better than "weird" empty lines for admins/users //TODO: should we remove all those @ before the header()? Are all of the values supported on all servers? header('Last-Modified: '. gmdate('D, d M Y H:i:s', $lastmodified) .' GMT'); // if user is using IE, urlencode the filename so that multibyte file name will show up correctly on popup if (check_browser_version('MSIE')) { // $filename = urlencode($filename); // (FS_CONVERTER) :ここから if (strlen(rawurlencode($filename)) > 21 * 3 * 3) { $filename = mb_convert_encoding($filename, "SJIS-WIN", "UTF-8"); $filename = str_replace('#', '%23', $filename); } else { $filename = rawurlencode($filename); } } else if (check_browser_version('Safari')) { $filename = ""; // (FS_CONVERTER):ここまで } if ($forcedownload) { // 半角空白を含むファイル名を与えると半角空白以降が欠けたファイル名になる問題 // @header('Content-Disposition: attachment; filename='.$filename); // (FS_CONVERTER) @header('Content-Disposition: attachment; filename="'.$filename.'"'); // (FS_CONVERTER) } else { // @header('Content-Disposition: inline; filename='.$filename); // (FS_CONVERTER) @header('Content-Disposition: inline; filename="'.$filename.'"'); // (FS_CONVERTER) }