header 之 Content-type 应用
来源:互联网 发布:36o安全卫士mac 编辑:程序博客网 时间:2024/05/29 10:27
利用Content-Type,可以将输出内容,以不同的文档格式返回
setlocale(LC_ALL, 'en_US.UTF-8');
$filename = date('YmdHis') . '.xls';
$data = "返回excel文档,结果输出到文件名为".$filename."excel的文件里";
header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
header('Content-Disposition:attachment;filename=' . $filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
ob_clean();
echo $data;
重点参数解释:
Content-disposition
Content-disposition 是 MIME 协议的扩展,MIME 协议指示 MIME 用户代理如何显示附加的文件。当 Internet Explorer 接收到头时,它会激活文件下载对话框,它的文件名框自动填充了头中指定的文件名。(请注意,这是设计导致的;无法使用此功能将文档保存到用户的计算机上,而不向用户询问保存位置。)
服务端向客户端游览器发送文件时,如果是浏览器支持的文件类型,一般会默认使用浏览器打开,比如txt、jpg等,会直接在浏览器中显示,如果需要提示用户保存,就要利用Content-Disposition进行一下处理,关键在于一定要加上attachment:
Response.AppendHeader("Content-Disposition","attachment;filename=FileName.txt");
备注:这样浏览器会提示保存还是打开,即使选择打开,也会使用相关联的程序比如记事本打开,而不是IE直接打开了。
阅读全文
0 0
- header 之 Content-type 应用
- header('Content-Type:..')
- Content-Type Header Field
- php的header函数之设置content-type
- php的header函数之设置content-type
- php的header函数之设置content-type
- php的header函数之设置content-type
- php的header函数之设置content-type
- php的header函数之设置content-type
- php的header函数之设置content-type
- php的header函数之设置content-type
- php的header函数之设置content-type
- header Content-Type与文件类型
- header 中Content-type的种类
- PHP: header中Content-type的种类
- header中Content-type的种类
- header( "Content-Type: application/vnd.ms-excel")
- php header Content-Type类型小结
- 微信PK阿里出新功能,小马哥躺着赚钱!
- GYM
- 第11章 开发板做中继功能
- Java基础知识学习之路-07-第五章-面向对象(下)
- Python通过循环压缩字符串 例如aaabbbbaaccdde>>>a5b4c2d2e1
- header 之 Content-type 应用
- pyhton学习之ModuleNotFoundError: No module named 'win32api'错误
- 魅族手机连不上adb的解决方法
- 【opencv学习之十八】基本绘图工具line circle rectangle ellipse等
- PhotoShop CC 2017软件工具面板使用---吸管工具
- springmvc 传值的几种方法
- Win10及VS2015下的OpenGL相关类库和环境配置
- C++ 单例模式的
- 权限学习--Shiro入门学习