Content-type 的说明
如果要将查询结果导出到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 的说明的更多相关文章
- Jsoup问题---获取http协议请求失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.
Jsoup问题---获取http协议请求失败 1.问题:用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不 ...
- Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.
用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 请求代码如下: private static ...
- SharePoint自动化系列——Add content type to list.
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish c ...
- SharePoint自动化系列——Content Type相关timer jobs一键执行
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 背景: 在SharePoint Central Administration->Monito ...
- 转载 SharePoint【Site Definition 系列】– 创建Content Type
转载原地址: http://www.cnblogs.com/wsdj-ITtech/archive/2012/09/01/2470274.html Sharepoint本身就是一个丰富的大容器,里面 ...
- the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header
the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header ...
- Springs Element 'beans' cannot have character [children], because the type's content type is element-only
Springs Element 'beans' cannot have character [children], because the type's content type is element ...
- springboot 报错 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
开始 controller 方法写的是 @RequestMapping( value = "/add", method = RequestMethod.POST ) public ...
- .NET获取文件的MIME类型(Content Type)
第一种:这种获取MIME类型(Content Type)的方法需要在.NET 4.5之后才能够支持,但是非常简单. 优点:方便快捷 缺点:只能在.NET 4.5之后使用 public FileResu ...
- 万能的ctrl+shift+F(Element 'beans' cannot have character [children], because the type's content type is element-only.错误)
今天在spring-servlet.xml文件中出现了一个莫名其妙的错误:Element 'beans' cannot have character [children], because the t ...
随机推荐
- iOS 开发--NSMutableArray使用枚举方法
可变数组也可以使用枚举方法, 我们在这里提供了两种枚举方法, 一个是正序枚举, 一个是倒序枚举, 在正序枚举中, 元素的个数和顺序都是不可以修改的, 但是在倒序枚举中却可以修改, 这有些耐人寻味. 涉 ...
- MyBatis学习总结_16_Mybatis使用的几个建议
1.Mapper层参数为Map,由Service层负责重载. Mapper由于机制的问题,不能重载,参数一般设置成Map,但这样会使参数变得模糊,如果想要使代码变得清晰,可以通过service层来实现 ...
- 很赞的MathJax
一直想在网页上放进LaTeX布局,但由于是要发布在SAE上,因此有很多的限制. 然后在这儿发现了这个好东东,MathJax,非常方便,JS直接可以外链. 通过它,我编辑了这个页面,看起来很不错哦.
- Linux系统中的load average
1. load average 定义 linux系统中的Load对当前CPU工作量的度量.简单的说是进程队列的长度. Load Average 就是一段时间 (1 分钟.5分钟.15分钟) 内平均 L ...
- Python应用与实践【转】
转自:http://www.cnblogs.com/skynet/archive/2013/05/06/3063245.html 目录 1. Python是什么? 1.1. Pyt ...
- js获取项目根路径
//js获取项目根路径,如: http://localhost:8083/uimcardprj function getRootPath(){ //获取当前网址,如: http://localhost ...
- python下载图片
import re import urllib.request def getHtml(url): page = urllib.request.urlopen(url) html = page. ...
- php注册登录系统(一)-极简
序 登录注册系统是日常上网最普通的操作,我设了一个分类一步步完善注册登录系统,若有哪里错误请慧教 所用语言:php 数据库 :mysql 本次实现功能: 1.用户注册 2.用户登录 主要文件: 完整代 ...
- Android项目真的要去做混淆(加密)处理
以前做项目做是懒得混淆代码,因为要处理各种第三方的混淆东西,像友盟里面加了第三方库,又要特殊处理混淆操作,所以很麻烦,也懒得去做混淆操作,so 你懂的:但今天我用一个反编译工具,发现一个很可怕的事情 ...
- HTML+CSS+JAVASCRIPT 总结
1. HTML 1: <!doctype html> 2: <!-- This is a test html for html, css, javascript --> 3: ...