如果要将查询结果导出到Excel,只需将页面的Context-Type修改一下就可以了:
   header( "Content-Type: application/vnd.ms-excel">
如果希望能够提供那个打开/保存的对话框,Content-Disposition参数,Content-Disposition参数本来是为了在客户端另存文件时提供一个建议的文件名,但是考虑到安全的原因,就从规范中去掉了这个参数
Content-Disposition参数:
attachment --- 作为附件下载   
inline --- 在线打开
具体使用如:header("Content-Disposition: inline; filename=文件名.mp3");
            Header("Content-Disposition:attachment;filename=test.xls");
其实IE是根据Content-Disposition中filename这个段中文件名的后缀来识别这个文件类型的,所以,
如果有很多种文件类型的时候,可以将Content-Type设置为二进制模式的:
            Header("Content-type:   application/octet-stream");
示例:
<?
$filename   =   './download/d.rar ';
$filesize   =   filesize($filename);
header( "Content-Type:   application/force-download ");
header( "Content-Disposition:   attachment;   filename= ".basename($filename));
header( "Content-Length:   ".$filesize);
$data   =   file_get_contents($filename);
echo   $data;
?>
这段代码的意识是打开页面后立即出现下载保存窗口,下载的文件为$filename,
摘取了常用的部分,其实还有其他一些
$mimetypes = array(
    'doc'        => 'application/msword',
    'bin'        => 'application/octet-stream',
    'exe'        => 'application/octet-stream',
    'so'        => 'application/octet-stream',
    'dll'        => 'application/octet-stream',
    'pdf'        => 'application/pdf',
    'ai'        => 'application/postscript',
    'xls'        => 'application/vnd.ms-excel',
    'ppt'        => 'application/vnd.ms-powerpoint',
    'dir'        => 'application/x-director',
    'js'        => 'application/x-javascript',
    'swf'        => 'application/x-shockwave-flash',
    'xhtml'        => 'application/xhtml+xml',
    'xht'        => 'application/xhtml+xml',
    'zip'        => 'application/zip',
    'mid'        => 'audio/midi',
    'midi'        => 'audio/midi',
    'mp3'        => 'audio/mpeg',
    'rm'        => 'audio/x-pn-realaudio',
    'rpm'        => 'audio/x-pn-realaudio-plugin',
    'wav'        => 'audio/x-wav',
    'bmp'        => 'image/bmp',
    'gif'        => 'image/gif',
    'jpeg'        => 'image/jpeg',
    'jpg'        => 'image/jpeg',
    'png'        => 'image/png',
    'css'        => 'text/css',
    'html'        => 'text/html',
    'htm'        => 'text/html',
    'txt'        => 'text/plain',
    'xsl'        => 'text/xml',
    'xml'        => 'text/xml',
    'mpeg'        => 'video/mpeg',
    'mpg'        => 'video/mpeg',
    'avi'        => 'video/x-msvideo',
    'movie'        => 'video/x-sgi-movie',  
);
 

Content-Type: application/vnd.ms-excel">的更多相关文章

  1. springboot 报错 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

    开始 controller 方法写的是 @RequestMapping( value = "/add", method = RequestMethod.POST ) public ...

  2. ajax使用向Spring MVC发送JSON数据出现 org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported错误

    ajax使用向Spring MVC发送JSON数据时,后端Controller在接受JSON数据时报org.springframework.web.HttpMediaTypeNotSupportedE ...

  3. jmeter报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported"的解决方法

    1.报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supporte ...

  4. Jmeter发送post请求报错Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

    常识普及: Content-type,在Request Headers里面,告诉服务器,我们发送的请求信息格式,在JMeter中,信息头存储在信息头管理器中,所以在做接口测试的时候,我们维护Conte ...

  5. Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

    Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported告诉你,你的请求头是application/x- ...

  6. org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported

    最后找到我的问题,springmvc配置文件中没加 <mvc:annotation-driven/> java代码: @RequestMapping(value="/reques ...

  7. 接入WxPusher微信推送服务出现错误:Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

    背景 使用WxPusher微信推送服务 ,可以及时的将服务的一些运行异常信息,发送到自己的微信上,方便了解服务的运行状态(PS:这个服务是免费的). 你可以在这里看到WxPusher微信推送服务的接入 ...

  8. Content type 'application/json;charset=UTF-8' not supported异常的解决过程

    首先说一下当时的场景,其实就是一个很简单的添加操作,后台传递的值是json格式的,如下图 ,后台对应的实体类, @Data @EqualsAndHashCode(callSuper = false) ...

  9. org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported或其他Content type不支持处理

    很久没从头到尾搭框架,今天搭的过程中,springmvc controller方法入参用@RequestBody自动绑定参数时一直提示各种 not supported 排查问题有两个解决路径: 1)使 ...

  10. SpringMVC在使用JSON时报错信息为:Content type 'application/json;charset=UTF-8' not supported

    直接原因是:我的(maven)项目parent父工程pom.xml缺少必要的三个jar包依赖坐标. 解决方法是:在web子模块的pom.xml里面添加springMVC使用JSON实现AJAX请求. ...

随机推荐

  1. MySql安装出现问题---无服务,修改密码

           之前在项目中一直使用的是SqlServer数据库,现在学习下MySql,下面是学习MySql的学习笔记. MySql简介       MySql是一种关联数据库管理系统(关系型),将数据 ...

  2. JS框架avalon简单例子 行编辑 添加 修改 删除 验证

    为什么要写这个例子:做表单的时候,表单包含主子表,对于子表的编辑,使用的是easyui datagrid的行编辑功能,由于业务比较复杂,实现起来比较麻烦,代码写的也很多,因为插件的封装,无法操作原始的 ...

  3. Expression<Func<TObject, bool>>与Func<TObject, bool>的区别

    Func<TObject, bool>是委托(delegate) Expression<Func<TObject, bool>>是表达式 Expression编译后 ...

  4. C# ~ 由 IDisposable 到 GC

    IDisposable 接口 1. 托管资源和非托管资源   ·  托管资源  a.  CLR 控制和管理的内存资源,如程序中在 Heap 上分配的对象.作用域内的变量等:  b.  GC 机制实现自 ...

  5. Xcode开发工具问题

    昨天打开Xcode 发现鼠标光标变成了黑色的块状,不能编辑内容了,且Content区域还多出了一个显示文件路径的框框 如下图: 然后自己百度,到论坛提问.到QQ群里问;卸载重装Xcode.重装系统各种 ...

  6. Windows Server 2012中配置AD域服务

    1.安装完AD域服务后,我们返回服务器管理器界面,点击"将此服务器提升为域控制器",选择"添加新林". 输入域名称:contoso.com 2.按图中所示选择林 ...

  7. 修复 XE8 for Android 方向传感器 headingX,Y,Z 不会动的问题

    问题:XE8 for Android 方向传感器无法正常运作(在 XE7 是正常的) 测试:官方示例 Samples\Object Pascal\Mobile Snippets\Orientation ...

  8. 专业PHP 7 IDE - Eclipse PDT 4.0 终于出世

    2016年6月22日,第一款开源免费的完整支持PHP 7版本的IDE - PDT 4终于发布.原本我是期望Netbeans 8.2的,但PDT 4.0 发布,就等不及了. PDT团队很高兴的宣布PDT ...

  9. 理解 OpenStack 高可用(HA) (4): Pacemaker 和 OpenStack Resource Agent (RA)

    本系列会分析OpenStack 的高可用性(HA)概念和解决方案: (1)OpenStack 高可用方案概述 (2)Neutron L3 Agent HA - VRRP (虚拟路由冗余协议) (3)N ...

  10. GJM :FPSCalc-简单FPS观测类 [转载]

    版权声明:本文原创发表于 [请点击连接前往] ,未经作者同意必须保留此段声明!如有侵权请联系我删帖处理! FPSCalc--简单FPS观测类 利用Unity做的手游项目很多时候要保证流畅度,流畅度最直 ...