« 上一篇下一篇 »

这样看来,程序必须得这样写才能支持所有主流浏览器:

这样看来,程序必须得这样写才能支持所有主流浏览器:

<?php

$ua = $_SERVER["HTTP_USER_AGENT"];// $_SERVER["HTTP_USER_AGENT"]在IE中显示为:
// Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko

$filename = "中文 文件名.txt";
$encoded_filename = urlencode($filename);
$encoded_filename = str_replace("+", "%20", $encoded_filename);

header('Content-Type: application/octet-stream');//if (preg_match("/MSIE/", $ua)) {        
//兼容IE11if(preg_match("/MSIE/", $ua) || preg_match("/Trident\/7.0/", $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';?>