一、下载任意文件:

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等浏览器的更多相关文章

  1. IE/Firefox/Chrome等浏览器保存Cookie的位置

    IE/Firefox/Chrome等浏览器保存Cookie的位置 原文  http://smilejay.com/2013/04/browser-cookie-location/   前面写了篇长文( ...

  2. js 获取页面高度和宽度(兼容 ie firefox chrome),获取鼠标点击位置

    <script> //得到页面高度 var yScroll = (document.documentElement.scrollHeight >document.documentEl ...

  3. 写一个trim函数,兼容IE firefox chrome(正则)

    因为在获取输入框内容时,常常trim下多余的空格.而IE部分低端浏览器里的JavaScript版本不内置trim()这个清楚空格函数,而流行的浏览器里都兼容了,比如chrome,FF等.为了不让IE下 ...

  4. 兼容ie\firefox\chrome的cursor

    cursor:hand 与 cursor:pointer 的效果是一样,都像手形光标. 但用FireFox浏览时才注意到使用cursor:hand在FireFox.chorme里并被支持.cursor ...

  5. JavaScript无提示关闭当前页面窗口,兼容IE/Firefox/Chrome

    <script type="text/javascript" language="javascript"> function fc(){ var b ...

  6. css zoom属性兼容ie,firefox,chrome

    jquery代码: $("body").css({ "zoom":"2", "transform":"scal ...

  7. 简单明了区分IE,Firefox,chrome主流浏览器

    简单明了判断浏览器Firefox:typeof navigator !== 'undefined' && navigator.userAgent.toLowerCase().index ...

  8. IE6/IE7/IE8/Firefox/Chrome/Safari的CSS hack兼容一览表

    浏览器兼容问题一直是前段开发工程师比较头痛的问题,熟悉了里面的规则也就变得简单了,这里有一份资料可以分享给大家,大家平时开发过程中遵循这个规律的话,会变得轻松多了: 各浏览器CSS hack兼容表: ...

  9. Javascript实例技巧精选(7)—设置和获取文本框与文本域的光标位置(兼容IE和Chrome,Firefox)

    >>点击这里下载完整html源码<< 截图如下: 本实例描述了如何用Javascript来控制和获取文本框/文本域的鼠标光标位置,以下代码兼容IE和Chrome,Firefox ...

  10. 在页面左右一个悬浮div兼容IE6 IE7 8 9 Firefox chrome

    在页面左右一个悬浮div兼容IE6 IE7 8 9 Firefox chrome #identifier-pannel { bottom: 345px; margin-left: 512px; pos ...

随机推荐

  1. [转载]Unity3D 游戏引擎之使用C#语言建立本地数据库(SQLITE)

    以前在开发中一直使用IOS源生的数据库,通过传递消息的形式在与Unity3D中进行交互.本文我在详细说说如何使用C#语言来在MAC 操作系统下创建Unity本地数据库,我是C#控哇咔咔--- 首先你需 ...

  2. uva 10271

    DP  状态转移方程 dp[i][j] = min(dp[i-1][j], dp[i-2][j-1] + w)) dp[i][j] 指的是前i个筷子组成j组所花费的最小值 考虑第i个筷子是否参与第j组 ...

  3. Kafka server的的停止

    这算是CountDownLatch的一个典型使用场景. kafka.Kafka对象的main方法中与此有关的代码为 // attach shutdown handler to catch contro ...

  4. FreeMarker 乱码解决方案 生成静态html文件

    读取模板的时候有一个编码: Template template = this.tempConfiguration.getTemplate(templatePath,"UTF-8") ...

  5. UIcollectionView的使用(首页的搭建1)

    今天做一个首页的效果:  首页是用UICollectionView做的.下面我来结合首页的效果介绍一下: 一.创建基类继承自UIViewController 01 创建基类继承自UIViewContr ...

  6. SVN使用方法总结

    SVN使用方法   SVN版本管理模式:http://www.cnblogs.com/newstar/archive/2011/01/04/svn.html (集中式-trunk和分散式-branch ...

  7. WCF的通信

    [ServiceContract]    public interface IContractDemoOne    {        [OperationContract(IsOneWay=true) ...

  8. 优化tomcat——jvm

    Tomcat 的启动参数位于tomcat的安装目录\bin目录下,如果你是Linux操作系统就是catalina.sh文件,如果你是Windows操作系统那么你需要改动的就是catalina.bat文 ...

  9. Vim Gtags插件

    01.Gtags func:查看定义处 02.Gtags -r func:查看引用处 03.Gtags -s text:查看未被数据库定义的tags 04.copen:打开quick fix显示窗口 ...

  10. Ubuntu 12.04本地编译安装Vim

    1.下载Vim,参考http://www.vim.org/git.php 2.编译安装Vim,参考https://github.com/Valloric/YouCompleteMe/wiki/Buil ...