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

yipeiwu_com6年前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';
?>

希望本文所述对大家的php程序设计有所帮助。

相关文章

在WAMP环境下搭建ZendDebugger php调试工具的方法

在WAMP环境下搭建ZendDebugger php调试工具的方法

东西不是新货,所以介绍就不做介绍了,下面主要是配置流程。   首先,下载ZendDebugger,下载链接:http://downloads.zend.com/pdt/server-d...

php中switch与ifelse的效率区别及适用情况分析

本文实例分析了php中switch与ifelse的效率区别及适用情况。分享给大家供大家参考。具体分析如下: PHP中的这两个方法都是用于判断值是否满足条件,如果满足/不满足做出不同行为动...

PHP连接及操作PostgreSQL数据库的方法详解

本文实例讲述了PHP连接及操作PostgreSQL数据库的方法。分享给大家供大家参考,具体如下: PostgreSQL扩展在默认情况下在最新版本的PHP 5.3.x中是启用的。 可以在编...

thinkphp Apache配置重启Apache1 restart 出错解决办法

概要:   thinkphp 在Apache上配置启用伪静态,重启Apache1 restart 竟然失败了,报错     Job for httpd.service failed be...

理解php原理的opcodes(操作码)

Opcondes是一种php脚本编译后的中间语言,就像Java的Byte Code,或者.NET 的MSL 。(都没了解过~)   举个文中的例子 复制代码 代码如下: <?php...