1. //定义编码
  2. header( 'Content-Type:text/html;charset=utf-8 ');
  3. //Atom
  4. header('Content-type: application/atom+xml');
  5. //CSS
  6. header('Content-type: text/css');
  7. //Javascript
  8. header('Content-type: text/javascript');
  9. //JPEG Image
  10. header('Content-type: image/jpeg');
  11. //JSON
  12. header('Content-type: application/json');
  13. //PDF
  14. header('Content-type: application/pdf');
  15. //RSS
  16. header('Content-Type: application/rss+xml; charset=ISO-8859-1');
  17. //Text (Plain)
  18. header('Content-type: text/plain');
  19. //XML
  20. header('Content-type: text/xml');
  21. // ok
  22. header('HTTP/1.1 200 OK');
  23. //设置一个404头:
  24. header('HTTP/1.1 404 Not Found');
  25. //设置地址被永久的重定向
  26. header('HTTP/1.1 301 Moved Permanently');
  27. //转到一个新地址
  28. header('Location: http://www.example.org/');
  29. //文件延迟转向:
  30. header('Refresh: 10; url=http://www.example.org/');
  31. print 'You will be redirected in 10 seconds';
  32. //当然,也可以使用html语法实现
  33. // <meta http-equiv="refresh" content="10;http://www.example.org/ />
  34. // override X-Powered-By: PHP:
  35. header('X-Powered-By: PHP/4.4.0');
  36. header('X-Powered-By: Brain/0.6b');
  37. //文档语言
  38. header('Content-language: en');
  39. //告诉浏览器最后一次修改时间
  40. $time = time() - 60; // or filemtime($fn), etc
  41. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
  42. //告诉浏览器文档内容没有发生改变
  43. header('HTTP/1.1 304 Not Modified');
  44. //设置内容长度
  45. header('Content-Length: 1234');
  46. //设置为一个下载类型
  47. header('Content-Type: application/octet-stream');
  48. header('Content-Disposition: attachment; filename="example.zip"');
  49. header('Content-Transfer-Encoding: binary');
  50. // load the file to send:
  51. readfile('example.zip');
  52. // 对当前文档禁用缓存
  53. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
  54. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  55. header('Pragma: no-cache');
  56. //设置内容类型:
  57. header('Content-Type: text/html; charset=iso-8859-1');
  58. header('Content-Type: text/html; charset=utf-8');
  59. header('Content-Type: text/plain'); //纯文本格式
  60. header('Content-Type: image/jpeg'); //JPG***
  61. header('Content-Type: application/zip'); // ZIP文件
  62. header('Content-Type: application/pdf'); // PDF文件
  63. header('Content-Type: audio/mpeg'); // 音频文件
  64. header('Content-Type: application/x-shockw**e-flash'); //Flash动画
  65. //显示登陆对话框
  66. header('HTTP/1.1 401 Unauthorized');
  67. header('WWW-Authenticate: Basic realm="Top Secret"');
  68. print 'Text that will be displayed if the user hits cancel or ';
  69. 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的更多相关文章

  1. php的header函数之设置content-type

    //定义编码 header( 'Content-Type:text/html;charset=utf-8 '); //Atom header('Content-type: application/at ...

  2. $_REQUEST变量数组header()函数

    $_SERVER 包含http信息头,路径和服务器端的一些信息,没发送一次HTTP请求,就会创建一个$_SERVER数组Array ( [HTTP_HOST] => localhost [HTT ...

  3. PHP header() 函数详细说明(301、404等错误设置)

    原文来自:http://www.veryhuo.com/a/view/41466.html 如果您刚刚开始学习PHP,可能有许多函数需要研究,今天我们就来学习一下PHP Header()的使用方法,更 ...

  4. the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header

    the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header ...

  5. PHP 使用header函数设置HTTP头的示例解析 表头

    PHP 使用header函数设置HTTP头的示例解析 表头 //定义编码 header( 'Content-Type:text/html;charset=utf-8 '); //Atom header ...

  6. PHP header函数设置http报文头(设置头部域)

    PHP HTTP 简介: HTTP 函数允许您在其他输出被发送之前,对由 Web 服务器发送到浏览器的信息进行操作. PHP 5 HTTP 函数:header()     向客户端发送原始的 HTTP ...

  7. php header()函数设置页面Cache缓存

    header()函数在php的使用很大,下面我来介绍利用它实现页面缓存的一些方法,但使用header前必须注意,在它之前不能任何输出,包括空格. 手册上,我们对于cache都是写着如何设置,以便让代码 ...

  8. (转载)PHP使用header函数设置HTTP头的示例方法表头

    (转载)http://justcoding.iteye.com/blog/601117/ 代码: //定义编码 header( 'Content-Type:text/html;charset=utf- ...

  9. PHP 使用header函数设置HTTP头的示例方法 表头 (xlsx下载)

    转载 http://justcoding.iteye.com/blog/601117/ //定义编码header( 'Content-Type:text/html;charset=utf-8 '); ...

随机推荐

  1. 修改文件中的内容,使用fileinput模块

    import fileinput filename = 'passwd' ,backup='.bak') print line.replace('root','ROOT') a = ' this is ...

  2. 理解v$sql的exact_matching_signature与force_matching_signature

    理解v$sql的exact_matching_signature与force_matching_signature 对SQL语句,去掉重复的空格(不包括字符常量),将大小写转换成相同,比如均为大写(不 ...

  3. java中的类修饰符、成员变量修饰符、方法修饰符。

    类修饰符: public(访问控制符),将一个类声明为公共类,他可以被任何对象访问,一个程序的主类必须是公共类. abstract,将一个类声明为抽象类,没有实现的方法,需要子类提供方法实现. fin ...

  4. PostgreSQL Partitions

    why we need partitions The first and most demanding reason to use partitions in a database is to inc ...

  5. 模拟退火法(吊打XXX)Bzoj3680

    3680: 吊打XXX Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special Judge Submit: 308  Solved: 94 [Subm ...

  6. poj1703 Find them, Catch them 并查集

    poj(1703) Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26992   ...

  7. nyist28大数阶乘

    http://acm.nyist.net/JudgeOnline/problem.php?pid=28 大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 我们 ...

  8. 深度解析 Java 内存原型

    一.Java 虚拟机内存原型 寄存器:我们在程序中无法控制. 栈:存放基本类型的数据和对象的引用,但对象本身不存放在栈中,而是存放在 堆中. 堆:存放用 new 产生的数据. 静态域:存放在对象中用  ...

  9. asp,asp.net 以表格输出excel,数据默认科学计数的解决办法

    关键字:  style="vnd.ms-excel.numberformat:@" 问题:在用table仿excel生成中经常遇到类似于身份证的长整数类型excel默认当成科学计数 ...

  10. 一个标准的ECharts代码

    <!DOCTYPE html> <head> <meta charset="utf-8"> <title>ECharts</t ...