php中利用header设置content-type和常见文件类型的content-type

php中利用header设置content-type和常见文件类型的content-typephp中利用header设置content-type和常见文件类型的content-type在PHP中可以通过header函数来发送头信息,还可以设置文件的content-type,下面整理了一些常见文件类型对于的content-type值。部分header头参考:http://www.lai18.com/content/433566.html//aut


Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

php中利用header设置content-type和常见文件类型的content-type

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

部分header头参考:
http://www.lai18.com/content/433566.html

//author http://www.lai18.com 
//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';

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/172650.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • ▲ Android 动画望远镜效果

    ▲ Android 动画望远镜效果

    2021年3月12日
  • php递归函数详解_用php递归函数实现阶乘计算

    php递归函数详解_用php递归函数实现阶乘计算本节内容:PHP递归算法。PHP递归算法代码:复制代码代码示例://定义PI一分的角度的值define(“PII”,M_PI/180);//新建图像资源,并定义其背景为白色,前景色为黑色$im=imagecreate(670,500);$white=imagecolorallocate($im,0xFF,0xFF,0xFF);$g=imagecolorallocate($im,0x00,0x0…

    2022年8月11日
  • ettercap的使用帮助文档 官方man page的个人理解

    ettercap的使用帮助文档 官方man page的个人理解原英文的帮助文档可以在http://linux.die.net/man/8/ettercap查看或者在安装有ettercap的Linux终端输入”manettercap”查看多数以我自己的理解的方式翻译,不是很理解的地方翻译过来的可能会有很多不对的地方如果对我翻译的内容有不一样的看法,欢迎交流。Nameettercap0.7.5-Amultipurposesniffer/co

    2022年6月28日
  • sqljdbc4.jar和sqljdbc.jar下载「建议收藏」

    sqljdbc4.jar和sqljdbc.jar下载「建议收藏」官网下载:windows版本http://go.microsoft.com/fwlink/?LinkId=144633&amp;clcid=0x804UNIX版本http://go.microsoft.com/fwlink/?LinkId=144635&amp;clcid=0x804  推荐几个网站:http://maven.ibiblio.org/maven/http…

    2022年7月16日
  • Django之模板语法

    注:以下内容转载自:https://www.cnblogs.com/haiyan123/p/7725568.html一、模板语法之变量:语法为{{}}:在Django模板中遍历复杂数据结构

    2021年12月29日
  • eagleEye_分析特性

    eagleEye_分析特性EagleEye是一个利用移动设备进行人脸识别的系统,在多人环境下,低像素的输入仍能够保持正确性这里关注的点分为两个部分: ContentAdaptivepipelineselection SpatialIndependenceandParallelism 内容自适应的流程选择(ContentAdaptivepipelineselection)这项技巧用于优化复杂的多DNN人脸识别pipeline的执行,并且还能保持高的正确率…

    2022年8月16日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号