Content-Type: application/vnd.ms-excel"

若是要將查詢結果導出到Excel,只需將頁面的Context-Type修改一下就能夠了:javascript

   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;filename=′./download/d.rar′;filesize   =   filesize(filename);header("ContentType:application/forcedownload");header("ContentDisposition:attachment;filename=".basename(filename);header("Content−Type:application/force−download");header("Content−Disposition:attachment;filename=".basename(filename));
header( "Content-Length:   ".filesize);filesize);data   =   file_get_contents(filename);echofilename);echodata;
?>
這段代碼的意識是打開頁面後當即出現下載保存窗口,下載的文件爲filenamefilename,摘取了經常使用的部分,其實還有其餘一些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',  
);
 
相關文章
相關標籤/搜索