體整有三個問題需克服
1. basename(); 當開頭為中文字時,會判斷錯誤,而將檔名去除
2. move_uploaded_file(); 無法處理 unicode 的中文檔案
3. imce 的顯示檔案清單也無法正常顯示 big5檔名,處理中文檔名上亦有問題
因此, 我利用 urlencode 將中文檔名轉碼上載儲存, 然後在顯示部分用 urldecode 將其還原顯示,這樣一來就可解決中文檔名上傳與顯示問題, 也不用更動太多地方
修改方式如下
drupal -> includes\file.inc
修正一 //約在571行
function file_save(stdClass $file) {
$file->filename = urldecode($file->filename); //加入,將儲存檔名還原為原始資料,實際儲存檔名仍為 urlencode() 後名稱
...
$file->filename = urlencode($file->filename); //加入,還原讓後續程序仍以 urlencode() 後名稱運作
unset($file->original);
return $file;
}
修正二 // Begin building file object. 約在1428行
// 程式內不一律採用 urlencode() 後名稱才不會產生中文問題(包含其他非英文語系)
$file = new stdClass();
$file->uid = $user->uid;
$file->status = 0;
$file->filename = trim(basename(urlencode($_FILES['files']['name'][$source])), '.'); //更動前 --> $file->filename = trim(basename($_FILES['files']['name'][$source]), '.');
修正三 //約在2374行 解決IE下載中文檔名問題
function file_get_content_headers($file) {
$name = mime_header_encode($file->filename);
//加入下列碼
if(isset($_SERVER['HTTP_USER_AGENT'])) {
if(preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT'])) {//判斷是否為 IE
$name = mime_header_encode(urlencode($file->filename));
}
}
...
imce\js\imce.js
//IMCE檔案顯示清單是將顯示檔名與實際檔案連結均使用相同變數, 所以必須將其分開,讓顯示檔名與實際聯結使用不同編碼格式
fileAdd: function(file) {
var row, i = imce.findex.length, attr = ['name', 'size', 'width', 'height', 'date'];
var fid = file.fid; // 更動前 fid = file.name
if (!(row = imce.fids[fid])) {
row = imce.findex[i] = imce.fids[fid] = imce.tbody.insertRow(i);
for (var i in attr) row.insertCell(i).className = attr[i];
}
row.id = fid; //新增
row.cells[0].innerHTML = file.name; //更動前 --> row.cells[0].innerHTML = row.id = fid;
....
}
imce\tpl\imce-file-list.tpl.php
<td class="name"><?php print urldecode($file['name']); ?></td> 更動前 --> <td class="name"><?php print $raw; ?></td>
imce\inc\imce.page.inc
修改一 約在262行
//check if there is any illegal choice
for ($i = 0; $i < $cnt; $i++) {
$filenames[$i] = $filename = $filenames[$i]; //更動前 --> $filenames[$i] = $filename = rawurldecode($filenames[$i]);
...
修正二 //約在278行, 修正顯示檔名問題
function imce_upload_submit($form, &$form_state) {
...
//原始 drupal_set_message(t('%filename has been uploaded.', array('%filename' => $file->filename)));
drupal_set_message(t('%filename has been uploaded.', array('%filename' => urldecode($file->filename) )));
...
修正三 //約在334行, 修正顯示檔名問題
function imce_delete_submit($form, &$form_state) {
...
if (!empty($deleted)) {
//原始drupal_set_message(t('File deletion successful: %files.', array('%files' => utf8_encode(implode(', ', $deleted)))));
drupal_set_message(t('File deletion successful: %files.', array('%files' => urldecode(implode(', ', $deleted))))); //shioulo
}
修改四 約在565行
function imce_add_file($file, &$imce) {
....
if (isset($_GET['jsop'])) {
....
$add['fid'] = rawurlencode($file->filename); //新增
$add['name'] = urldecode($file->filename); //更動前 --> $add['name'] = rawurlencode($file->filename);