jquery教程

推荐列表 站点导航

当前位置:首页 > jquery > jquery教程 >

跨浏览器下PHP下载文件名中的中文乱码问题的解决方法

来源:网络整理  作者:网友投稿  发布时间:2020-12-27 22:23
跨浏览器下PHP下载文件名中的中文乱码问题的解决方法,有需要的朋友可以看看。...

跨浏览器下PHP下载文件名中的中文乱码问题的解决方法,有需要的朋友可以看看。
 

复制代码 代码如下:

<?php
$ua = $_SERVER["HTTP_USER_AGENT"];

$filename = "中文 文件名.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';
?>
 

上面是一个比较通用的解决方案(据说xp+IE7会有问题,未验证)。

这个问题是在使用CI-Excel-Generation-Library时遇到的,解决办法:
 

复制代码 代码如下:

<?php
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 ");
   }
?>

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jq/jc/9881.shtml

相关文章
最新文章
PHP识别相片是否是颠倒的 PHP识别相片是否是颠倒的

时间:2020-12-28

python编程有哪些ide python编程有哪些ide

时间:2020-12-28

python开发工程师是做什么 python开发工程师是做什么

时间:2020-12-28

php构造函数的作用 php构造函数的作用

时间:2020-12-28

php怎么跟数据库连接 php怎么跟数据库连接

时间:2020-12-28

php实现顺序线性表 php实现顺序线性表

时间:2020-12-28

Python多重继承中的菱形继 Python多重继承中的菱形继

时间:2020-12-28

php中break的作用 php中break的作用

时间:2020-12-28

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

跨浏览器下PHP下载文件名中的中文乱码问题的解决方法

2020-12-27 编辑:网友投稿

跨浏览器下PHP下载文件名中的中文乱码问题的解决方法,有需要的朋友可以看看。
 

复制代码 代码如下:

<?php
$ua = $_SERVER["HTTP_USER_AGENT"];

$filename = "中文 文件名.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';
?>
 

上面是一个比较通用的解决方案(据说xp+IE7会有问题,未验证)。

这个问题是在使用CI-Excel-Generation-Library时遇到的,解决办法:
 

复制代码 代码如下:

<?php
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 ");
   }
?>

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jq/jc/9881.shtml

相关文章

风云图片

推荐阅读

返回jquery教程频道首页