php的header()函數之設定content-type

來源:互聯網
上載者:User

標籤:blog   http   io   os   ar   使用   java   for   sp   

  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

 

php的header()函數之設定content-type

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.