国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開發(fā) > PHP > 正文

php中header設(shè)置常見文件類型的content-type

2024-05-04 23:36:49
字體:
供稿:網(wǎng)友

這篇文章主要介紹了php中header設(shè)置常見文件類型的content-type的相關(guān)資料,需要的朋友可以參考下

在PHP中可以通過header函數(shù)來發(fā)送頭信息,還可以設(shè)置文件的content-type,下面整理了一些常見文件類型對(duì)于的content-type值。

 

 
  1. //date 2015-06-22 
  2. //定義編碼 
  3. header( 'Content-Type:text/html;charset=utf-8 '); 
  4.  
  5. //Atom 
  6. header('Content-type: application/atom+xml'); 
  7.  
  8. //CSS 
  9. header('Content-type: text/css'); 
  10.  
  11. //Javascript 
  12. header('Content-type: text/javascript'); 
  13.  
  14. //JPEG Image 
  15. header('Content-type: image/jpeg'); 
  16.  
  17. //JSON 
  18. header('Content-type: application/json'); 
  19.  
  20. //PDF 
  21. header('Content-type: application/pdf'); 
  22.  
  23. //RSS 
  24. header('Content-Type: application/rss+xml; charset=ISO-8859-1'); 
  25.  
  26. //Text (Plain) 
  27. header('Content-type: text/plain'); 
  28.  
  29. //XML 
  30. header('Content-type: text/xml'); 
  31.  
  32. // ok 
  33. header('HTTP/1.1 200 OK'); 
  34.  
  35. //設(shè)置一個(gè)404頭: 
  36. header('HTTP/1.1 404 Not Found'); 
  37.  
  38. //設(shè)置地址被永久的重定向 
  39. header('HTTP/1.1 301 Moved Permanently'); 
  40.  
  41. //轉(zhuǎn)到一個(gè)新地址 
  42. header('Location: http://www.example.org/');  
  43. //文件延遲轉(zhuǎn)向: 
  44. header('Refresh: 10; url=http://www.example.org/'); 
  45. print 'You will be redirected in 10 seconds'
  46.  
  47. //當(dāng)然,也可以使用html語(yǔ)法實(shí)現(xiàn) 
  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. //文檔語(yǔ)言 
  55. header('Content-language: en'); 
  56.  
  57. //告訴瀏覽器最后一次修改時(shí)間 
  58. $time = time() - 60; // or filemtime($fn), etc 
  59. header('Last-Modified: '.gmdate('D, d M Y H:i:s'$time).' GMT'); 
  60.  
  61. //告訴瀏覽器文檔內(nèi)容沒有發(fā)生改變 
  62. header('HTTP/1.1 304 Not Modified'); 
  63.  
  64. //設(shè)置內(nèi)容長(zhǎng)度 
  65. header('Content-Length: 1234'); 
  66.  
  67. //設(shè)置為一個(gè)下載類型 
  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. // 對(duì)當(dāng)前文檔禁用緩存 
  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. //設(shè)置內(nèi)容類型: 
  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動(dòng)畫 
  88.  
  89. //顯示登陸對(duì)話框 
  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'

以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宁晋县| 泽普县| 阜新市| 那坡县| 鄂伦春自治旗| 新蔡县| 桑植县| 临泉县| 淮南市| 余庆县| 卓尼县| 邮箱| 西城区| 弥勒县| 湘潭市| 百色市| 昌宁县| 旬邑县| 汕尾市| 金门县| 绍兴市| 余庆县| 巩留县| 山东省| 荃湾区| 偃师市| 和政县| 连江县| 洪江市| 荥经县| 榆林市| 东平县| 万全县| 张北县| 临洮县| 莒南县| 宜良县| 新和县| 手游| 含山县| 玉环县|