在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';

php设置文件类型content-type的更多相关文章

  1. .NET获取文件的MIME类型(Content Type)

    第一种:这种获取MIME类型(Content Type)的方法需要在.NET 4.5之后才能够支持,但是非常简单. 优点:方便快捷 缺点:只能在.NET 4.5之后使用 public FileResu ...

  2. html input file 设置文件类型

    解决方案: 使用 input 的 accept 属性指定接受文件类型 -----------更新--------------- 之前的代码有个缺点,打开文件窗口时会自动筛选文件夹下所有符合设定类型的文 ...

  3. sharepoint 2010 如何创建文档库内容类型content type

    转:http://biancheng.dnbcw.info/linux/441643.html 这次主要是记录下,如何来创建文档内容类型,例如新建文档的时候,可以选择不同模板,有word,excel文 ...

  4. Java怎样获取Content-Type的文件类型Mime Type

    在Http请求中.有时须要知道Content-Type类型,尤其是上传文件时.更为重要.尽管有些办法可以解决,但都不太准确或者繁琐,索性我发现一个开源的类库可以解决相对完美的解决问题,它就是jMime ...

  5. sublime text3设置文件类型(CR/LF)

  6. WebStorm文件类型关联设置

    无意中创造了一个没有扩展名的文件,我选择了错误的文件类型关联.是js类型的,我却选成了文本,Ws每次编辑类型就成了txt文本,这个问题让我很苦恼,以下是我的解决方案. 错选的弹出框如下: 解决方案如下 ...

  7. <input type="file"> accept属性筛选文件类型

    如果你不希望用户上传任何类型的文件, 你可以使用 input 的 accept 属性. 设置支持 .doc / .docx / .xls / .xlsx / .pdf 格式: <input ty ...

  8. <input type="file" />浏览时只显示指定文件类型

    <input type="file" />浏览时只显示指定文件类型 <input type="file" accept="appli ...

  9. 转载 SharePoint【Site Definition 系列】– 创建Content Type

    转载原地址:  http://www.cnblogs.com/wsdj-ITtech/archive/2012/09/01/2470274.html Sharepoint本身就是一个丰富的大容器,里面 ...

随机推荐

  1. 毕向东_Java基础视频教程第20天_IO流(15~17)

    第20天-15-IO流(打印输出流) 打印输出流:PrintWriter与PrintStream 两者的区别:Since JDK 1.4 it's possible to specify the ch ...

  2. iTextSharp 使用详解(转)

    PDF文件是目前比较流行的电子文档格式,在办公自动化(OA)等软件的开发中,经常要用到该格式,但介绍如何制作PDF格式文件的资料非常少,在网上搜来搜去,都转贴的是同一段“暴力”破解的方法,代码片断如下 ...

  3. Linux学习---Linux安装ftp组件

    1 安装vsftpd组件 安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件. [root@bogon ~]# yum -y install vsftpd 2 添 ...

  4. Foj 2299 Prefix(AC自动机、DP)

    Foj 2299 Prefix 题意 给定串s.正整数n,问有多少长度为n的字符串t满足:s[0...i]是t的子串,s[0...i+1]不是. 题解 求有多少长度为n的字符串t满足:s[0...i] ...

  5. extern “C”

    http://www.cnblogs.com/yc_sunniwell/archive/2010/07/14/1777431.html 问题:extern “C” 在C++环境下使用C函数的时候,常常 ...

  6. 根据自增ID生成不重复序列号

    网上看到一个例子,源地址:https://www.aliyun.com/jiaocheng/536419.html 借鉴修改一下 实现根据long类型的用户ID生成6位随机邀请码,并且根据邀请码能算出 ...

  7. VirtualBox操作总结

    1. VirtualBox安装 下载rpm,rpm -ivh 安装 2. 在图形界面打开virtual box virtualbox 3. vboxmanage打开虚拟机 vboxmanage sta ...

  8. 4种方法获取select下拉框标签中的值

    选中下拉框中“上海” 代码如下:<select id="province" class="select" name="province" ...

  9. 使用Jwt为.Net Core SignalR保驾护航

    前言 SignalR Demo搭建起来之后,是没有相应的认证和授权功能的.于是乎,参考官方文档实现了相应的逻辑. 简单认证 首先使用稍微简单的方式实现.添加如下代码: services.AddAuth ...

  10. POJ 1050 To the Max 最大子矩阵和(二维的最大字段和)

    传送门: http://poj.org/problem?id=1050 To the Max Time Limit: 1000MS   Memory Limit: 10000K Total Submi ...