复制蔽或代码
代码如下:
<?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'])
?>
解决PHP
Header下载文件在IE文件名中文乱码有两种常见的,一种是是把页面编码改成utf8,另一种是对中文url进入urlencode编码就可以解决了。
解决方案一(我清烂的页面是utf-8编码):
复制代码
代码如下:
$filename
=
"中文.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
.
'"')
}
解决方法二
将文宏正伍件名先urlencode一下再放入header,如下。
代码如下:
复制代码
代码如下:
<?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'])
?>
解决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: attachmentfilename="' . $encoded_filename . '"肢槐')
} else if (preg_match("/Firefox/", $ua)) {
header('Content-Disposition: attachmentfilename*="utf8\'\'扒饥中' . $filename . '"')
} else {
header('Content-Disposition: attachmentfilename="' . $filename . '"')
}
?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)