In the middle of a problem is the submission of the Chinese file name directly into the header under IE will become garbled, the solution is to urlencode the file name first and then put in the header, as follows.
The code is as follows:
<?php $file _name = urlencode ($_request[' 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/vnd.ms-excel; Charset=utf-8 '); Header ("Content-transfer-encoding:binary"); Header (' content-disposition:attachment; filename= '. $file _name); echo stripslashes ($_request[' content ');?>
Solve the PHP header download file in the IE file name garbled there are two common, one is to change the page encoding to UTF8, the other is the Chinese URL into the UrlEncode code can be solved.
Solution One (my page is utf-8 encoded):
The code is as follows:
$filename = "Chinese. txt"; $ua = $_server["Http_user_agent"]; $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. '"'); }
Workaround Two
UrlEncode the file name first and then put it in the header, as follows.
The code is as follows:
The code is as follows:
<?php $file _name = urlencode ($_request[' 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/vnd.ms-excel; Charset=utf-8 '); Header ("Content-transfer-encoding:binary"); Header (' content-disposition:attachment; filename= '. $file _name); echo stripslashes ($_request[' content ');?>
The above is win7 display file suffix php force download the file code (solve the IE Chinese file name garbled problem) content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!