php ie8使用a标签下载,PHP 文件下载 兼容ie8,ie7,google chrome

header('Content-Description: File Transfer');

header('Cache-Control: private, must-revalidate,post-check=0, pre-check=0, max-age=1');//这句兼容低版本ie

//header('Pragma: public');

header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past

header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');

header('Content-Type: image/gif');

// use the Content-Disposition header to supply a recommended filename

header('Content-Disposition: attachment; filename='.$saveFileName);

header('Content-Transfer-Encoding: binary');

echo file_get_contents($file);

exit;

-----------------------------------------------------------------------------------大文件下载存在问题,修改成下面的下载方式--------------------------------------

$path =‘data/test.exe’;  $mm_type="application/octet-stream"; // modify accordingly to the file type of $path, but in most cases no need to do so $filesize = filesize($path); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Type: " . $mm_type); header("Content-Length: " .$filesize ); header('Content-Disposition: attachment; filename="'.basename($path).'"'); header("Content-Transfer-Encoding: binary\n"); $chunksize = 1 * (1024 * 1024); // how many bytes per chunk  if ($filesize > $chunksize) {   $handle = fopen($path, 'rb');   $buffer = '';   while (!feof($handle)) {  $buffer = fread($handle, $chunksize);  echo $buffer;  ob_flush();  flush();   }   fclose($handle);  } else {   readfile($path);  }  //readfile($path); // outputs the content of the file exit();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值