An error occurred while exporting the Chinese file name in phpexcel. header ("Content-Disposition: attachment; filename = $ filename ");
$ If filename is Chinese, the downloaded file is. php in English.
Reply to discussion (solution)
Try
$user_agent = $_SERVER['Http_User_agent']; $encode_filename = rawurlencode($filename); if(preg_match("/MSIE/", $user_agent)){ header('content-disposition:attachment; filename="'.$encode_filename.'"'); }else if(preg_match("/Firefox/", $user_agent)){ header("content-disposition:attachment; filename*=\"utf8''".$filename.'"'); }else{ header('content-disposition:attachment; filename="'.$filename.'"'); }
Try
$user_agent = $_SERVER['Http_User_agent']; $encode_filename = rawurlencode($filename); if(preg_match("/MSIE/", $user_agent)){ header('content-disposition:attachment; filename="'.$encode_filename.'"'); }else if(preg_match("/Firefox/", $user_agent)){ header("content-disposition:attachment; filename*=\"utf8''".$filename.'"'); }else{ header('content-disposition:attachment; filename="'.$filename.'"'); }
Opening and downloading the file seems to be the first text to solve the problem.
1. header ("Content-Disposition: attachment; filename = $ filename"); must be a pure file name without a path
2. the default character set of phpexcel is utf-8. most people use UTF-8, which is a waste of resources, to save program files. This may inevitably have a BOM header.
In fact, Microsoft is very considerate. it only uses dual bytes for non-English systems (UTF-8 Chinese is 3 bytes)
If a person cannot understand double-byte Chinese, he cannot understand 3-byte Chinese! So what do you call globalization?
1. header ("Content-Disposition: attachment; filename = $ filename"); must be a pure file name without a path
2. the default character set of phpexcel is utf-8. most people use UTF-8, which is a waste of resources, to save program files. This may inevitably have a BOM header.
Solved. thank you!