webfm模組的檔案上傳中文問題。最近使用到此模組遇到中文檔名問題。
查了滿多資料。不知有沒有人有使用過此模組?
它本身的webfm_upload是只上傳檔案至相對的目錄
function webfm_upload () {
global $user;
// /獲取目標路徑的編輯webfmuploadpath隱藏字段中上傳表單
$json_data = array();
$fid = '';
if(isset($_POST['webfmuploadpath'])) {
$root_dir = (($user->uid == 1) || user_access('administer webfm'))? file_directory_path() : file_directory_path().webfm_get_root_path();
$dest = $root_dir.$_POST['webfmuploadpath'];
//保存新的文件上傳到tmp dir.(正確路徑)
if(($file = file_save_upload('webfm_upload')) != FALSE) {
//縮放image上傳。
_webfm_image($file);
$err_arr = array();
if(webfm_upload_validate($file, $err_arr) === TRUE) {
/// /文件已被放在臨時,我們有一個有效的文件對象
/// /緩存文件路徑為$ _SESSION 給 ajax confirm 確認名稱衝突
$upload_path = $dest.'/'.$file->filename;
if(is_file($upload_path)) {
$file->in_db = ($webfm_file_row = webfm_get_file_record('', $upload_path)) ? TRUE : FALSE;
$file->dest = $dest;
$_SESSION['temp_upload'] = $file;
$json_data['file'] = $file->filename;
if($file->in_db) {
//覆蓋現有檔案在資料庫中
//只有管理員,檔案所有者或修改的文件被標記為可以覆蓋的作用
if(($webfm_file_row->uid == $user->uid) ||
user_access('administer webfm') ||
webfm_file_mod_access($webfm_file_row)) {
$json_data['html'] = webfm_reload_upload('webfm/upload', webfm_version_form($file->filename));
} else {
drupal_set_message(t('Permission denied to overwrite existing file'), 'error');
}
} else {
//覆蓋現有文件不是在數據庫
$msg = '';
if(($fid = webfm_version_upload(WEBFM_REPLACE_RENAME, $msg)) !== FALSE) {
// file was inserted into the database
drupal_set_message($msg);
} else {
drupal_set_message($msg, 'error');
}
}
} else if(file_move($file, $dest)) {
// file was moved to its final destination
// Insert file into database
if(($fid = webfm_dbinsert_file($file, $db_err)) !== FALSE) {
drupal_set_message(t('Upload Success'));
} else {
file_delete($file->filepath);
drupal_set_message($db_err, 'error');
}
} else {
drupal_set_message(t('file_move to %path failed', array('%path' => $dest)), 'error');
}
} else {
foreach($err_arr as $err) {
drupal_set_message($err, 'error');
}
}
} else {
if(!isset($_FILES['files']) || $_FILES['files']['name']['webfm_upload'] == '') {
drupal_set_message(t('Please click "Browse" and select a file to upload before clicking the upload button.'), 'error');
}
}
} else {
drupal_set_message(t('Invalid upload path'), 'error');
}
if(!isset($json_data['html']))
$json_data['html'] = webfm_reload_upload('webfm/upload');
if($fid)
$json_data['fid'] = $fid;
print drupal_to_js(array('status' => TRUE, 'data' => $json_data));
exit();
}
/**
若因為metadate問題,詢問什麼是比較好的解決方式。
引用阿舍網址:http://drupal.soa.tw/webfm_module_setting_part2