<br /><br />$arr = array(1,2,3,4);<br />$file_data = json_encode($res);<br />$download_filename = '123.json';<br />$http_user_agent = $_SERVER['HTTP_USER_AGENT'];<br />header("Content-Type: application/octet-stream");<br />if (preg_match("/MSIE/", $http_user_agent) ) {<br />    header('Content-Disposition:  attachment; filename="'.$download_filename.'"');<br />} elseif (preg_match("/Firefox/", $http_user_agent)) {<br />    header ('Content-Disposition: attachment; filename*="utf8' . $download_filename . '"' );<br />} else {<br />    header('Content-Disposition:  attachment; filename="'.$download_filename.'"');<br />}<br />header("Accept-Length: ".strlen($file_data));<br />echo $file_data;<br /><br />试了试,谷歌浏览器、火狐浏览器可直接下载;<br />IE浏览器如果出现如下弹窗:
php下载文件
解决方案:在ie菜单栏的【页面】-->【编码】,选择【自动选择】然后下载试试。<br /><br />360浏览器也出现这种问题,待测。
<br /><br /><br />