Solution to Chinese garbled characters in PHP file names downloaded in different browsers
$ Ua = $ _ SERVER ["HTTP_USER_AGENT"];
$ Filename = "Chinese file name .txt ";
- $ Encoded_filename = urlencode ($ filename );
- $ Encoded_filename = str_replace ("+", "% 20", $ encoded_filename );
Header ('content-Type: application/octet-stream ');
If (preg_match ("/MSIE/", $ ua )){
- Header ('content-Disposition: attachment; filename = "'. $ encoded_filename .'"');
- } Else if (preg_match ("/Firefox/", $ ua )){
- Header ('content-Disposition: attachment; filename * = "utf8 \ '\''. $ filename .'"');
- } Else {
- Header ('content-Disposition: attachment; filename = "'. $ filename .'"');
- }
Print 'abc ';
- ?>
-
The above is a common solution (it is said that xp + IE7 has problems and is not verified ). This problem occurs when CI-Excel-Generation-Library is used. solution:
Private function set_headers (){
- $ Ua = $ _ SERVER ["HTTP_USER_AGENT"];
- $ Filename = $ this-> filename. ". xls ";
- $ Encoded_filename = urlencode ($ filename );
- $ Encoded_filename = str_replace ("+", "% 20", $ encoded_filename );
Header ("Pragma: public ");
- Header ("Expires: 0 ");
- Header ("Cache-Control: must-revalidate, post-check = 0, pre-check = 0 ");
- Header ("Content-Type: application/force-download ");
- Header ("Content-Type: application/octet-stream ");
// Header ("Content-Type: application/vnd. ms-excel; charset = UTF-8 ");
- Header ("Content-Type: application/download ");;
- If (preg_match ("/MSIE/", $ ua )){
- Header ('content-Disposition: attachment; filename = "'. $ encoded_filename .'"');
- } Else if (preg_match ("/Firefox/", $ ua )){
- Header ('content-Disposition: attachment; filename * = "utf8 \ '\''. $ filename .'"');
- } Else {
- Header ('content-Disposition: attachment; filename = "'. $ filename .'"');
- }
- Header ("Content-Transfer-Encoding: binary ");
- }
- ?>
|