php 实现文件下载,兼容IE、Firefox、Chrome等浏览器
一、下载任意文件:
Header ( "Content-type: application/octet-stream" );
$ua = $_SERVER ["HTTP_USER_AGENT"];
$file = '/var/www/tmp.txt';
$filename = basename ( $file );
$encoded_filename = rawurlencode ( $filename );
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 . '"' );
}
header ( "Content-Length: " . filesize ( $file ) );
readfile ( $file );
二、PHPExcel导出excel文件下载:
...
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
header('Content-Type: application/vnd.ms-excel');
$ua = $_SERVER["HTTP_USER_AGENT"];
$encoded_filename = rawurlencode($filename);
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 . '"');
}
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
php 实现文件下载,兼容IE、Firefox、Chrome等浏览器的更多相关文章
- IE/Firefox/Chrome等浏览器保存Cookie的位置
IE/Firefox/Chrome等浏览器保存Cookie的位置 原文 http://smilejay.com/2013/04/browser-cookie-location/ 前面写了篇长文( ...
- js 获取页面高度和宽度(兼容 ie firefox chrome),获取鼠标点击位置
<script> //得到页面高度 var yScroll = (document.documentElement.scrollHeight >document.documentEl ...
- 写一个trim函数,兼容IE firefox chrome(正则)
因为在获取输入框内容时,常常trim下多余的空格.而IE部分低端浏览器里的JavaScript版本不内置trim()这个清楚空格函数,而流行的浏览器里都兼容了,比如chrome,FF等.为了不让IE下 ...
- 兼容ie\firefox\chrome的cursor
cursor:hand 与 cursor:pointer 的效果是一样,都像手形光标. 但用FireFox浏览时才注意到使用cursor:hand在FireFox.chorme里并被支持.cursor ...
- JavaScript无提示关闭当前页面窗口,兼容IE/Firefox/Chrome
<script type="text/javascript" language="javascript"> function fc(){ var b ...
- css zoom属性兼容ie,firefox,chrome
jquery代码: $("body").css({ "zoom":"2", "transform":"scal ...
- 简单明了区分IE,Firefox,chrome主流浏览器
简单明了判断浏览器Firefox:typeof navigator !== 'undefined' && navigator.userAgent.toLowerCase().index ...
- IE6/IE7/IE8/Firefox/Chrome/Safari的CSS hack兼容一览表
浏览器兼容问题一直是前段开发工程师比较头痛的问题,熟悉了里面的规则也就变得简单了,这里有一份资料可以分享给大家,大家平时开发过程中遵循这个规律的话,会变得轻松多了: 各浏览器CSS hack兼容表: ...
- Javascript实例技巧精选(7)—设置和获取文本框与文本域的光标位置(兼容IE和Chrome,Firefox)
>>点击这里下载完整html源码<< 截图如下: 本实例描述了如何用Javascript来控制和获取文本框/文本域的鼠标光标位置,以下代码兼容IE和Chrome,Firefox ...
- 在页面左右一个悬浮div兼容IE6 IE7 8 9 Firefox chrome
在页面左右一个悬浮div兼容IE6 IE7 8 9 Firefox chrome #identifier-pannel { bottom: 345px; margin-left: 512px; pos ...
随机推荐
- C#读取网页源码
#region 1.读取 网页源码 + static string ReadHtml(string urlStr,int type) /// <summary> /// 读取 网页源码 + ...
- PAT-乙级-1013. 数素数 (20)
1013. 数素数 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 令Pi表示第i个素数.现任给两个正整 ...
- setTimeout浅析
刚学习javascript的时候,感觉setTimeout很好理解,不就是过n(传入的毫秒数)毫秒,执行以下传入的函数吗?这个理解伴随了我挺长的一段时间,才对setTimeout有了新的认识,请先看下 ...
- spoj 178
输出相邻的点 比较简单吧....... #include <cstdio> #include <cstring> using namespace std; int main ...
- "Principles of Reactive Programming" 之<Actors are Distributed> (1)
week7中的前两节课的标题是”Actors are Distributed",讲了很多Akka Cluster的内容,同时也很难理解. Roland Kuhn并没有讲太多Akka Clus ...
- 一个只需要点 「下一步」就完成监控 Windows
Cloud Insight 此前已然支持 Linux 操作系统,支持20多中数据库中间件等组件,多种操作,多种搭配,服务器监控玩的其乐无穷啊!但想想还有许多 Windows 的小伙伴没有体验过,所以在 ...
- linux后台执行命令&
当在前台运行某个作业时,终端被该作业占据:而在后台运行作业时,它不会占据终端.可以使用&命令把作业放到后台执行. 如:30 2 * * * /data/app/scripts/hotbacku ...
- 使用JS创建表格以及隔行换色(包括隔N行换色)
<html> <head> <title></title> <style> table{ width:800px; border-colla ...
- 李洪强漫谈iOS开发[C语言-014]-变量
01 变量的概念 02 - 变量的语法 03 变量的使用
- UIWebView和UIWebViewDelegate的基本用法
UIWebView和UIWebViewDelegate的基本用法 一.UIWebView主要有三种方法实现页面的装载,分别是: 1. (void)loadRequest:(NSURLRequest * ...