首页 > Web开发 > 详细

php下载文件

时间:2018-01-20 16:03:41      阅读:159      评论:0      收藏:0      [点我收藏+]


$arr = array(1,2,3,4);
$file_data = json_encode($res);
$download_filename = ‘123.json‘;
$http_user_agent = $_SERVER[‘HTTP_USER_AGENT‘];
header("Content-Type: application/octet-stream");
if (preg_match("/MSIE/", $http_user_agent) ) {
header(‘Content-Disposition: attachment; filename="‘.$download_filename.‘"‘);
} elseif (preg_match("/Firefox/", $http_user_agent)) {
header (‘Content-Disposition: attachment; filename*="utf8‘ . $download_filename . ‘"‘ );
} else {
header(‘Content-Disposition: attachment; filename="‘.$download_filename.‘"‘);
}
header("Accept-Length: ".strlen($file_data));
echo $file_data;

试了试,谷歌浏览器、火狐浏览器可直接下载;
IE浏览器如果出现如下弹窗:

技术分享图片

解决方案:在ie菜单栏的【页面】-->【编码】,选择【自动选择】然后下载试试。

360浏览器也出现这种问题,待测。



php下载文件

原文:https://www.cnblogs.com/gyfluck/p/8320762.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!