--- file.php.orig0	2007-06-14 17:49:10.000000000 +0900
+++ file.php	2007-06-14 17:51:54.000000000 +0900
@@ -164,6 +164,22 @@
     // ========================================
     session_write_close(); // unlock session during fileserving
     $filename = $args[count($args)-1];
+   $ua = $_SERVER['HTTP_USER_AGENT'];
+   if (strstr($ua, "MSIE") && !strstr($ua, 'Opera')) {
+      $filename = mb_convert_encoding($filename, "SJIS",
+    get_string('thischarset'));
+   } elseif (strstr($ua, "Safari")) {
+      if (get_string('thischarset') == "UTF-8") {
+         $filename = "";
+      } else {
+         $filename = preg_replace('/[^\.a-zA-Z\d\_-]/', '_',
+    $filename);
+      }
+   } else {
+      $filename = mb_convert_encoding($filename, "UTF-8",
+    get_string('thischarset'));
+   }
+   $filename = str_replace('#', '%23', $filename);
     send_file($pathname, $filename, $lifetime, $CFG->filteruploadedfiles, false, $forcedownload);
 
     function not_found($courseid) {
