上传LINUX文件出乱码!
php:我在上传文件到LINUX下面一个指定的目录时,中文文件名都会变成一个个问号? 涩兔子你帮我试试好吗?谢谢了! 贴出测试URL :mrgreen:一定要使用utf-8进行编码 代码写上来好吗?谢了,好人!
$upload_file = isset($_FILES['attach_article']['name']) ? $_FILES['attach_article']['name'] : '';
$upload_tmp_file = isset($_FILES['attach_article']['tmp_name']) ? $_FILES['attach_article']['tmp_name'] : '';
$upload_dir = getcwd() . "/uploads/attach_article/";
$filename = $upload_dir . $upload_file;
$pinfo = pathinfo($filename);
$extension = $pinfo[extension];
$sql = "SELECT unsafe_extension
FROM " . TABLE_PREFIX . "unsafe_ext
WHERE unsafe_extension = '$extension' ";
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$result = $db->Execute($sql);
if (!$result) {
echo $db->ErrorMsg();
} else {
$row = $result->fetchRow(ADODB_FETCH_ASSOC);
}
if ( !$row ) {
if ( !empty($upload_file) ) {
if ( !file_exists($filename) ) {
if ( move_uploaded_file($upload_tmp_file, $filename) ) {
$upload_time = time();
$user_id = $_SESSION['user_id'];
$sql = "SELECT username
FROM " . TABLE_PREFIX . "users
WHERE user_id = '$user_id' ";
$username = $db->getOne($sql);
$upload_user = $username;
$sql = "INSERT INTO " . TABLE_PREFIX . "attach_article(attach_name, attach_desc,
upload_time, username, sub_cat_id)
VALUES ('$upload_file', '$attach_desc', '$upload_time', '$upload_user', '$sub_cat_id') " ;
if ($db->Execute($sql) === false) {
echo 'error inserting: '.$db->ErrorMsg().'<BR>';
} else {
$sql = "SELECT attach_name
FROM " . TABLE_PREFIX . "attach_article
WHERE username = '$upload_user'
AND article_id = '0' ";
$upload_succeed_attach = $db->getCol($sql);
$template->assign(array(
"L_NOTE_POST" => sprintf($lang['upload_succeed'], count($upload_succeed_attach))
)
);
}
} else {
$template->assign(array(
"L_NOTE_POST" => sprintf($lang['upload_failed'], $upload_file)
)
);
}
} else {
$template->assign(array(
"L_NOTE_POST" => sprintf($lang['upload_exist'], $upload_file)
)
);
}
} else {
$template->assign(array(
"L_NOTE_POST" => $lang['null_attach_article']
)
);
}
} else {
$template->assign(array(
"L_NOTE_POST" => sprintf($lang['forbidden_upload_type'], $extension)
)
);
}
写入文件文件名的编码要和当前系统编码和 php 的编码一致。不然就需要转换了
页:
[1]