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. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');  
    75. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past  
    76. header('Pragma: no-cache');  
    77.   
    78. //设置内容类型:  
    79. header('Content-Type: text/html; charset=iso-8859-1');  
    80. header('Content-Type: text/html; charset=utf-8');  
    81. header('Content-Type: text/plain'); //纯文本格式  
    82. header('Content-Type: image/jpeg'); //JPG***  
    83. header('Content-Type: application/zip'); // ZIP文件  
    84. header('Content-Type: application/pdf'); // PDF文件  
    85. header('Content-Type: audio/mpeg'); // 音频文件  
    86. header('Content-Type: application/x-shockw**e-flash'); //Flash动画  
    87.   
    88. //显示登陆对话框  
    89. header('HTTP/1.1 401 Unauthorized');  
    90. header('WWW-Authenticate: Basic realm="Top Secret"');  
    91. print 'Text that will be displayed if the user hits cancel or ';  
    92. print 'enters wrong login data';  


    下载xlsx文件

      1. $filename = rtrim($_SERVER['DOCUMENT_ROOT'],'/').'/app/files/payment_status.csv';  
      2. header('Content-Disposition: attachment; filename=payment_status.xlsx');  
      3. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');  
      4. header('Content-Length: ' . filesize($filename));  
      5. header('Content-Transfer-Encoding: binary');  
      6. header('Cache-Control: must-revalidate');  
      7. header('Pragma: public');
      8. readfile($filename);

    转自:http://blog.csdn.net/kankan231/article/details/37929409

  • 相关阅读:
    Quartz cron表达式
    Apache NiFi 核心概念和关键特性
    Hive llap服务安装说明及测试(一)
    nifi生产环境使用
    DataX 中Transformer的使用
    vue2.0之过渡动画,分别用钩子函数,animated,原生css实现(前端网备份)
    js对对象数组的某一字段排序(前端网备份)
    浏览器之禁扒(前端网备份)
    iframe 从父像子穿参数(前端网备份)
    关于小程序仿微博导航效果(前端网备份 )
  • 原文地址:https://www.cnblogs.com/c-961900940/p/4064631.html
Copyright © 2011-2022 走看看