在PHP中可以通过header函数来发送头信息,还可以设置文件的content-type,下面整理了一些常见文件类型对于的content-type值。

//date 2015-06-22
//定义编码
header( 'Content-Type:text/html;charset=utf-8 ');
 
//Atom
header('Content-type: application/atom+xml');
 
//CSS
header('Content-type: text/css');
 
//Javascript
header('Content-type: text/javascript');
 
//JPEG Image
header('Content-type: image/jpeg');
 
//JSON
header('Content-type: application/json');
 
//PDF
header('Content-type: application/pdf');
 
//RSS
header('Content-Type: application/rss+xml; charset=ISO-8859-1');
 
//Text (Plain)
header('Content-type: text/plain');
 
//XML
header('Content-type: text/xml');
 
// ok
header('HTTP/1.1 200 OK');
 
//设置一个404头:
header('HTTP/1.1 404 Not Found');
 
//设置地址被永久的重定向
header('HTTP/1.1 301 Moved Permanently');
 
//转到一个新地址
header('Location: http://www.example.org/');
//文件延迟转向:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';
 
//当然,也可以使用html语法实现
// <meta http-equiv="refresh" content="10;http://www.example.org/ />
 
// override X-Powered-By: PHP:
header('X-Powered-By: PHP/4.4.0');
header('X-Powered-By: Brain/0.6b');
 
//文档语言
header('Content-language: en');
 
//告诉浏览器最后一次修改时间
$time = time() - 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
 
//告诉浏览器文档内容没有发生改变
header('HTTP/1.1 304 Not Modified');
 
//设置内容长度
header('Content-Length: 1234');
 
//设置为一个下载类型
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');
// load the file to send:
readfile('example.zip');
 
// 对当前文档禁用缓存
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');
 
//设置内容类型:
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain'); //纯文本格式
header('Content-Type: image/jpeg'); //JPG***
header('Content-Type: application/zip'); // ZIP文件
header('Content-Type: application/pdf'); // PDF文件
header('Content-Type: audio/mpeg'); // 音频文件
header('Content-Type: application/x-shockw**e-flash'); //Flash动画
 
//显示登陆对话框
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
print 'Text that will be displayed if the user hits cancel or ';
print 'enters wrong login data';

最新文章

  1. Python 编码简单说
  2. 真核转录组(denovo/resequencing)及案例分析
  3. Github克隆别人的库
  4. How Tomcat Works(十四)补充
  5. 用VirtualBox构建MySQL测试环境笔记
  6. weblogic开机启动脚本
  7. 浙大pat1013题解
  8. 人生第一次hash
  9. jmeter- Java-POST接口使用get与json格式传参
  10. 用keras实现基本的回归问题
  11. HTML 5 Web 本地存储
  12. H5新特性之geolocation
  13. 函数mmap()的使用
  14. linux安装软件的几种方式(kali平台)和一些实用的软件(持续更新)
  15. c/c++不能返回局部对象和局部变量的指针或引用解释
  16. Linux建立FTP服务器
  17. EOJ Problem #3249 状态压缩+循环周期+反向递推
  18. python 横向比较最大值 贴标签
  19. Codeforces Round #328(Div2)
  20. mq4参考

热门文章

  1. 从golang-gin-realworld-example-app项目学写httpapi (八)
  2. python之路——进程
  3. 使用iCarousel的旋转木马效果请求图片
  4. 辉光的UIView
  5. C++ 重载 重写 重定义
  6. Java学习---Quartz定时任务快速入门
  7. July 27th 2017 Week 30th Thursday
  8. redis下的持久化保存
  9. ubuntu 14.04 配置 java 环境
  10. 内存池-转载自IBM