zoukankan      html  css  js  c++  java
  • php的header函数之设置content-type

    1. //定义编码  
    2. header( 'Content-Type:text/html;charset=utf-8 ');  
    3.   
    4. //Atom  
    5. header('Content-type: application/atom+xml');  
    6.   
    7. //CSS  
    8. header('Content-type: text/css');  
    9.   
    10. //Javascript  
    11. header('Content-type: text/javascript');  
    12.   
    13. //JPEG Image  
    14. header('Content-type: image/jpeg');  
    15.   
    16. //JSON  
    17. header('Content-type: application/json');  
    18.   
    19. //PDF  
    20. header('Content-type: application/pdf');  
    21.   
    22. //RSS  
    23. header('Content-Type: application/rss+xml; charset=ISO-8859-1');  
    24.   
    25. //Text (Plain)  
    26. header('Content-type: text/plain');  
    27.   
    28. //XML  
    29. header('Content-type: text/xml');  
    30.   
    31. // ok  
    32. header('HTTP/1.1 200 OK');  
    33.   
    34. //设置一个404头:  
    35. header('HTTP/1.1 404 Not Found');  
    36.   
    37. //设置地址被永久的重定向  
    38. header('HTTP/1.1 301 Moved Permanently');  
    39.   
    40. //转到一个新地址  
    41. header('Location: http://www.example.org/');  
    42.   
    43. //文件延迟转向:  
    44. header('Refresh: 10; url=http://www.example.org/');  
    45. print 'You will be redirected in 10 seconds';  
    46.   
    47. //当然,也可以使用html语法实现  
    48. // <meta http-equiv="refresh" content="10;http://www.example.org/ />  
    49.   
    50. // override X-Powered-By: PHP:  
    51. header('X-Powered-By: PHP/4.4.0');  
    52. header('X-Powered-By: Brain/0.6b');  
    53.   
    54. //文档语言  
    55. header('Content-language: en');  
    56.   
    57. //告诉浏览器最后一次修改时间  
    58. $time = time() - 60; // or filemtime($fn), etc  
    59. header('Last-Modified: '.gmdate('D, d M Y H:i:s'$time).' GMT');  
    60.   
    61. //告诉浏览器文档内容没有发生改变  
    62. header('HTTP/1.1 304 Not Modified');  
    63.   
    64. //设置内容长度  
    65. header('Content-Length: 1234');  
    66.   
    67. //设置为一个下载类型  
    68. header('Content-Type: application/octet-stream');  
    69. header('Content-Disposition: attachment; filename="example.zip"');  
    70. header('Content-Transfer-Encoding: binary');  
    71. // load the file to send:  
    72. readfile('example.zip');  
    73.   
    74. // 对当前文档禁用缓存  
    75. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');  
    76. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past  
    77. header('Pragma: no-cache');  
    78.   
    79. //设置内容类型:  
    80. header('Content-Type: text/html; charset=iso-8859-1');  
    81. header('Content-Type: text/html; charset=utf-8');  
    82. header('Content-Type: text/plain'); //纯文本格式  
    83. header('Content-Type: image/jpeg'); //JPG***  
    84. header('Content-Type: application/zip'); // ZIP文件  
    85. header('Content-Type: application/pdf'); // PDF文件  
    86. header('Content-Type: audio/mpeg'); // 音频文件  
    87. header('Content-Type: application/x-shockw**e-flash'); //Flash动画  
    88.   
    89. //显示登陆对话框  
    90. header('HTTP/1.1 401 Unauthorized');  
    91. header('WWW-Authenticate: Basic realm="Top Secret"');  
    92. print 'Text that will be displayed if the user hits cancel or ';  
    93. print 'enters wrong login data';  
      1 Content-type 的说明
      2 
      3 $mimetypes = array(
      4  'ez' => 'application/andrew-inset',
      5  'hqx' => 'application/mac-binhex40',
      6  'cpt' => 'application/mac-compactpro',
      7  'doc' => 'application/msword',
      8  'bin' => 'application/octet-stream',
      9  'dms' => 'application/octet-stream',
     10  'lha' => 'application/octet-stream', 
     11  'lzh' => 'application/octet-stream',
     12  'exe' => 'application/octet-stream',
     13  'class' => 'application/octet-stream',
     14  'so' => 'application/octet-stream',
     15  'dll' => 'application/octet-stream',
     16  'oda' => 'application/oda',
     17  'pdf' => 'application/pdf',
     18  'ai' => 'application/postscript',
     19  'eps' => 'application/postscript',
     20  'ps' => 'application/postscript',
     21  'smi' => 'application/smil',
     22  'smil' => 'application/smil', 
     23 
     24  'mif' => 'application/vnd.mif',
     25  'xls' => 'application/vnd.ms-excel',
     26  'ppt' => 'application/vnd.ms-powerpoint',
     27  'wbxml' => 'application/vnd.wap.wbxml',
     28  'wmlc' => 'application/vnd.wap.wmlc',
     29  'wmlsc' => 'application/vnd.wap.wmlscriptc',
     30  'bcpio' => 'application/x-bcpio',
     31  'vcd' => 'application/x-cdlink',
     32  'pgn' => 'application/x-chess-pgn',
     33  'cpio' => 'application/x-cpio',
     34  'csh' => 'application/x-csh',
     35 
     36 'dcr' => 'application/x-director',
     37  'dir' => 'application/x-director',
     38  'dxr' => 'application/x-director',
     39  'dvi' => 'application/x-dvi',
     40  'spl' => 'application/x-futuresplash',
     41  'gtar' => 'application/x-gtar',
     42  'hdf' => 'application/x-hdf',
     43  'js' => 'application/x-javascript',
     44  'skp' => 'application/x-koan',
     45  'skd' => 'application/x-koan',
     46  'skt' => 'application/x-koan',
     47  'skm' => 'application/x-koan', 
     48  'latex' => 'application/x-latex',
     49  'nc' => 'application/x-netcdf',
     50  'cdf' => 'application/x-netcdf',
     51  'sh' => 'application/x-sh',
     52  'shar' => 'application/x-shar',
     53  'swf' => 'application/x-shockwave-flash',
     54  'sit' => 'application/x-stuffit',
     55  'sv4cpio' => 'application/x-sv4cpio',
     56  'sv4crc' => 'application/x-sv4crc',
     57  'tar' => 'application/x-tar',
     58  'tcl' => 'application/x-tcl',
     59  'tex' => 'application/x-tex', 
     60  'texinfo' => 'application/x-texinfo',
     61  'texi' => 'application/x-texinfo',
     62  't' => 'application/x-troff',
     63  'tr' => 'application/x-troff',
     64  'roff' => 'application/x-troff',
     65  'man' => 'application/x-troff-man',
     66  'me' => 'application/x-troff-me',
     67  'ms' => 'application/x-troff-ms',
     68  'ustar' => 'application/x-ustar',
     69  'src' => 'application/x-wais-source',
     70  'xhtml' => 'application/xhtml+xml',
     71  'xht' => 'application/xhtml+xml', 
     72  'zip' => 'application/zip',
     73  'au' => 'audio/basic',
     74  'snd' => 'audio/basic',
     75  'mid' => 'audio/midi',
     76  'midi' => 'audio/midi',
     77  'kar' => 'audio/midi',
     78  'mpga' => 'audio/mpeg',
     79  'mp2' => 'audio/mpeg',
     80  'mp3' => 'audio/mpeg',
     81  'aif' => 'audio/x-aiff',
     82  'aiff' => 'audio/x-aiff',
     83  'aifc' => 'audio/x-aiff',
     84  'm3u' => 'audio/x-mpegurl', 
     85  'ram' => 'audio/x-pn-realaudio',
     86  'rm' => 'audio/x-pn-realaudio',
     87  'rpm' => 'audio/x-pn-realaudio-plugin',
     88  'ra' => 'audio/x-realaudio',
     89  'wav' => 'audio/x-wav',
     90  'pdb' => 'chemical/x-pdb',
     91  'xyz' => 'chemical/x-xyz',
     92  'bmp' => 'image/bmp',
     93  'gif' => 'image/gif',
     94  'ief' => 'image/ief',
     95  'jpeg' => 'image/jpeg',
     96  'jpg' => 'image/jpeg',
     97  'jpe' => 'image/jpeg', 
     98  'png' => 'image/png',
     99  'tiff' => 'image/tiff',
    100  'tif' => 'image/tiff',
    101  'djvu' => 'image/vnd.djvu',
    102  'djv' => 'image/vnd.djvu',
    103  'wbmp' => 'image/vnd.wap.wbmp',
    104  'ras' => 'image/x-cmu-raster',
    105  'pnm' => 'image/x-portable-anymap',
    106  'pbm' => 'image/x-portable-bitmap',
    107  'pgm' => 'image/x-portable-graymap',
    108  'ppm' => 'image/x-portable-pixmap',
    109  'rgb' => 'image/x-rgb', 
    110  'xbm' => 'image/x-xbitmap',
    111  'xpm' => 'image/x-xpixmap',
    112  'xwd' => 'image/x-xwindowdump',
    113  'igs' => 'model/iges',
    114  'iges' => 'model/iges',
    115  'msh' => 'model/mesh',
    116  'mesh' => 'model/mesh',
    117  'silo' => 'model/mesh',
    118  'wrl' => 'model/vrml',
    119  'vrml' => 'model/vrml',
    120  'css' => 'text/css',
    121  'html' => 'text/html',
    122  'htm' => 'text/html', 
    123  'asc' => 'text/plain',
    124  'txt' => 'text/plain',
    125  'rtx' => 'text/richtext',
    126  'rtf' => 'text/rtf',
    127  'sgml' => 'text/sgml',
    128  'sgm' => 'text/sgml',
    129  'tsv' => 'text/tab-separated-values',
    130  'wml' => 'text/vnd.wap.wml',
    131  'wmls' => 'text/vnd.wap.wmlscript',
    132  'etx' => 'text/x-setext',
    133  'xsl' => 'text/xml',
    134  'xml' => 'text/xml',
    135  'mpeg' => 'video/mpeg',
    136 
    137 'mpg' => 'video/mpeg',
    138  'mpe' => 'video/mpeg',
    139  'qt' => 'video/quicktime',
    140  'mov' => 'video/quicktime',
    141  'mxu' => 'video/vnd.mpegurl',
    142  'avi' => 'video/x-msvideo',
    143  'movie' => 'video/x-sgi-movie',
    144  'ice' => 'x-conference/x-cooltalk',
    145 );

    The following table documents the HTTP MIME types that are available when working with Office 2007 documents:

    Ext

    MIME Type

    .doc

    application/msword

    .dot

    application/msword

    .docx

    application/vnd.openxmlformats-officedocument.wordprocessingml.document

    .dotx

    application/vnd.openxmlformats-officedocument.wordprocessingml.template

    .docm

    application/vnd.ms-word.document.macroEnabled.12

    .dotm

    application/vnd.ms-word.template.macroEnabled.12

    .xls

    application/vnd.ms-excel

    .xlt

    application/vnd.ms-excel

    .xla

    application/vnd.ms-excel

    .xlsx

    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

    .xltx

    application/vnd.openxmlformats-officedocument.spreadsheetml.template

    .xlsm

    application/vnd.ms-excel.sheet.macroEnabled.12

    .xltm

    application/vnd.ms-excel.template.macroEnabled.12

    .xlam

    application/vnd.ms-excel.addin.macroEnabled.12

    .xlsb

    application/vnd.ms-excel.sheet.binary.macroEnabled.12

    .ppt

    application/vnd.ms-powerpoint

    .pot

    application/vnd.ms-powerpoint

    .pps

    application/vnd.ms-powerpoint

    .ppa

    application/vnd.ms-powerpoint

    .pptx

    application/vnd.openxmlformats-officedocument.presentationml.presentation

    .potx

    application/vnd.openxmlformats-officedocument.presentationml.template

    .ppsx

    application/vnd.openxmlformats-officedocument.presentationml.slideshow

    .ppam

    application/vnd.ms-powerpoint.addin.macroEnabled.12

    .pptm

    application/vnd.ms-powerpoint.presentation.macroEnabled.12

    .potm

    application/vnd.ms-powerpoint.presentation.macroEnabled.12

    .ppsm

    application/vnd.ms-powerpoint.slideshow.macroEnabled.12

    学如逆水行舟,不进则退。
  • 相关阅读:
    P1983 车站分级
    P1807 最长路
    P1347 排序
    P1073 最优贸易 (tarjan缩点+dp)
    最小费用最大流解决KM匹配问题
    CF191C Fools and Roads
    case when
    防呆机制
    DbCommand :执行超时已过期。完成操作之前已超时或服务器未响应。
    存储过程带参数和sqlcommand
  • 原文地址:https://www.cnblogs.com/dhsx/p/4827926.html
Copyright © 2011-2022 走看看