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

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • C语言 stat 函数「建议收藏」

    C语言 stat 函数「建议收藏」C语言stat函数stat头文件:#include<sys/stat.h>#include<unistd.h>函数原型:intstat(constchar*file_name,structstat*buf)**函数说明:**stat函数获取file_name指向文件的文件状态,并将文件信息保存到结构体buf中,执行成功返回0,失…

    2022年8月21日
    17
  • matlab循环求和_r语言for循环计算求和

    matlab循环求和_r语言for循环计算求和题目描述编写程序求和S=a+aa+aaa+aaaa+…,其中a是1-9中的一个数字。n为一正整数,a和n均从键盘输入。(例如输入n为4,a为2,S=2+22+222+2222)输入两行整数,分别表示a,n输出一个整数样例输入Copy24样例输出Copy2468程序代码a=input(”);n=input(”);temp=0;sum=0;fori=1:ntemp=temp*10+a;sum

    2022年10月6日
    0
  • Delphi XE 5,Rad Studio XE 5 官方下载(附激活成功教程),更新 Update 1,Help Update 1

    Delphi XE 5,Rad Studio XE 5 官方下载(附激活成功教程),更新 Update 1,Help Update 1DelphiXE5激活成功教程,有图有真相EmbarcaderoRADStudioXE5Update2v19.0.14356.6604(等待激活成功教程中…):http://altd.embarcadero.com/download/radstudio/xe5/delphicbuilder_xe5_upd2_win.isohotfix_1_2_3_…

    2022年7月18日
    25
  • 彻底卸载Symantec Endpoint Protection之另类办法「建议收藏」

    彻底卸载Symantec Endpoint Protection之另类办法「建议收藏」诺顿卸载需要输入密码,网上一篇文章说终结进程的办法不适合v11,机器是单位的,所以开始并没有想到完全卸载,怕起不来,于是进入安全模式禁用所有服务,下个卡巴斯基安装,结果一安装,卡巴斯基就提示先卸载诺顿,太可爱了,点击确认之后,卸载之后再重启就卸得干干净净了,装上卡巴斯基,好几天也没死一次机,而以前一天要死一两次,诺顿真垃圾,而且卸载也卸不干净。卡巴斯基还有这个妙用啊,即使你不想安卡巴斯基,也可以用它来删诺顿,而且不用输密码,强。

    2022年5月27日
    58
  • webpackdevtool配置简单对比简书_钢铁雄心4toolpack

    webpackdevtool配置简单对比简书_钢铁雄心4toolpack官方手册传送门官方对devtool配置的定义很简单:选择一种sourcemap格式来增强调试过程,不同的值会明显影响到构建build和重新构建rebuild的速度。不过,什么是sourcemap,官方用提供了许多种的sourcemap,其中的区别是什么,我们在开发中应该怎么选择,都是我们要学习的。1.什么是sourcemap现在的前端代码会通过babel编译或者各类的…

    2022年9月29日
    0
  • BeanUtils.populate()的作用

    BeanUtils.populate()的作用//1.获得请求参数Map<String,String[]>map=request.getParameterMap();Useruser=newUser();//

    2022年7月4日
    22

发表回复

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

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