-
-
$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';
- ?>
-
-
Copy code
The above is a more general solution (it is said that xp+IE7 will have problems, but it has not been verified).
This problem was encountered when using CI-Excel-Generation-Library. The 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 ");
- }
- ?>< ;/p>
-
Copy code
|