XOOPS附件下載中文檔名會變成亂碼的解決方式

(參考: http://www.baddog.idv.tw/notebook.php?mo=notebook&fn=view&id=8)

☺ 因資料庫為UTF8格式,在有中文檔名時,不轉成BIG-5的話,IE下載回來的檔名會變亂碼 ☺

 

檔案: dl_attachment.php

if(!empty($GLOBALS["xoopsModuleConfig"]["download_direct"])):

 

header("Cache-Control: no-store, no-cache, must-revalidate");

header("Cache-Control: post-check=0, pre-check=0", false);

header("Pragma: no-cache");

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

header("location: ".XOOPS_URL.'/'.$xoopsModuleConfig['dir_attachments'].'/'.$attach['name_saved']);

 

else:

$file_display = mb_convert_encoding($attach['name_display'],"BIG-5","UTF-8");

$mimetype = $attach['mimetype'];

if (function_exists('mb_http_output')) {

           mb_http_output('pass');

}

header('Expires: 0');

header('Content-Type: '.$mimetype);

if (preg_match("/MSIE ([0-9]\.[0-9]{1,2})/", $HTTP_USER_AGENT)) {

           header('Content-Disposition: inline; filename="'.$file_display.'"');

           header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

           header('Pragma: public');

} else {

           header('Content-Disposition: attachment; filename="'.$file_display.'"');

           header('Pragma: no-cache');

}

header("Content-Type: application/force-download");

header("Content-Transfer-Encoding: binary");

 

$handle = fopen($file_saved, "rb");

while (!feof($handle)) {

   $buffer = fread($handle, 4096);

   echo $buffer;

}

fclose($handle);

 

endif;

 

 

附註: http://php.net/manual/en/function.mb-convert-encoding.php

mb_convert_encoding - Convert character encoding

string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding ] )

Converts the character encoding of string str to to_encoding from optionally from_encoding.

 

 

arrow
arrow
    文章標籤
    PHP XOOPS
    全站熱搜

    yunc 發表在 痞客邦 留言(0) 人氣()