Drupal本身默认使用UTF-8编码,提供优秀的多语言化工具,对多国语言有着优秀的支持。但在image模块中,我发现存在两个问题:一是部分中文文件名的图片文件不能正确地创建中间临时文件导致上传失败;二是管理员拼量Fast上传文件时除了发生第一个问题,自动生成的节点标题字符集是GB2312的(对我的Windows系统而言)。
解决方法如下:
对一:在function image_validate(&$node) 中的
// Move uploaded file to temp area
//$temp_file = variable_get("image_temp_path", "./")."tmpimg_".$upload_name; //注销此行
//改为:
$extend = pathinfo($upload_name);
$extend = strtolower($extend["extension"]);
$temp_file = variable_get("image_temp_path", "./")."tmpimg_".$node->image_id.".".$extend;
//即不使用原文件名作中间文件名
//----------insert above---------------
if (!move_uploaded_file($upload_file, $temp_file) && arg(3) != "file" ) {
$error["image"] = theme("error", t("Error processing image file."));
}
对二:
先必须解决一,在function _image_dir_upload($type = "slow", $edit = NULL) 中修改:
$basename = basename($file, strrchr($file, "."));
//----------------------------------------------
// 解决批量上传中文文件名从gb2312到UTF-8的转码问题
if (function_exists('iconv')) {
$basename = iconv('gb2312', 'utf-8', $basename);
}
//----------------------------------------------
if ($edit[$basename]["title"]) {
$node->title = $edit[$basename]["title"];
}
else {
$node->title = $basename;
}

