Content-Type: application/vnd.ms-excel">
2013-11-16 14:10
253 查看
如果要将查询结果导出到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',
);
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">
- Content-Type: application/vnd.ms-excel">
- header( "Content-Type: application/vnd.ms-excel")
- Response.ContentType = "application/vnd.ms-excel"
- header( "Content-Type: application/vnd.ms-excel")
- Content-Type: application/vnd.ms-excel
- Content-Type: application/vnd.ms-excel
- 为什么乱码:<meta http-equiv="content-type">前的非ANSI字符
- android 访问web 返回xml 的注意事项;<?xml version="1.0" encoding="UTF-8"?>前面不能有空格 且 contentType="text/xml;
- <meta http-equiv="Content-Type" content="text/html:charset=UTF-8">是什么意思?
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />是什么
- 获取 request 中用POST方式"Content-type"是"application/x-www-form-urlencoded;charset=utf-8"发送的 json 数据
- <META http-equiv=Content-Type content="text/html; charset=gb2312">
- <meta name="application-name" content="优酷网" /> 是什么意思?
- <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>意义
- 转 :meta name的含义:<META http-equiv=Content-Type content="text/html; charset=gb2312">
- android 上传文件"Content-Type",为"application/octet-stream" 用php程序在服务端用$GLOBALS['HTTP_RAW_POST_DATA']接受(二)
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />解释
- <%@page contentType="text/html;charset=GBK"%>与<meta content="text/html; charset=GBK">区别
- <meta charset="gbk">或者<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">乱码