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语言截取字符串_c语言截取字符串后2位

    C语言截取字符串_c语言截取字符串后2位GitHub-frankRenlf/c_dailyWork只需加入’\0’再输出字符串即可#include<stdio.h>voidtest4(){chararr[100];intk=0;while(scanf(“%s”,arr)!=EOF){scanf(“%d”,&k);arr[k]=’\0′;printf(“%s\n”,arr);}…

    2025年6月15日
    4
  • QueryInterface详解 COM

    QueryInterface详解 COMQueryInterface接口查询IUnknown:      所有的COM接口均需要继承IUnknown接口。因此,若某个用户拥有一个IUnknown接口指针,它并不需要知道它所拥有的接口指针到底是什么类型的,而只需要通过此接口就可以用来查询其他接口就行了。      由于所有的COM接口都继承了IUnknown,每个接口的vbtl的前三项都是QueryInterface,A

    2022年6月29日
    30
  • 2021-09-10 网安实验-XCTF真题实战之流量分析

    2021-09-10 网安实验-XCTF真题实战之流量分析通信流量分析使用Wireshark打开HEHEHE.pcap文件。对于通信流量分析类题目,常用的一个解法就是使用过滤器tcpcontains”.rar”来查看数据包中是否包含有rar文件,实际操作时rar可以换成zip等其他扩展名。现在在Wireshark的Filter编辑框中输入过滤器tcpcontains“.rar”,果然发了这样的通信记录,选中第一条结果,单击右键选择“FollowTCPStream”,可以看到数据包里存在一个rar文件,这里将其Dump出来(在窗口中选择Raw,然后点

    2022年5月22日
    52
  • 前端报错400

    前端报错400前端报错400看控制台报错:Resolved[org.springframework.web.method.annotation.MethodArgumentTypeMismatchException:Failedtoconvertvalueoftype’java.lang.String’torequiredtype’java.util.Date’;nestede…

    2022年6月11日
    86
  • RestSharp_C#

    RestSharp_C#usingRestSharp;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingLitJson;namespaceWarehouseManager{classHttpSend…

    2025年9月2日
    5
  • 程序员该不该去外包公司_程序员项目外包

    程序员该不该去外包公司_程序员项目外包最近,关于“外包”的话题,在程序员之间讨论得十分热烈。究竟什么叫外包呢?在IT行业,有些程序员在大公司的办公楼里,跟正式员工们一起工作。但是,他们并不隶属于这家公司,而是属于第三方公司,比如博彦科技,比如文思海辉,比如中软国际……这些人就像是后妈的孩子,他们的薪酬远不如大公司的正式工,上升空间也有限。他们有个共同的名字,叫做外包人员。那么,年轻的程序员们该不该进入…

    2022年9月30日
    1

发表回复

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

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