search
HomeBackend DevelopmentPHP TutorialUse header to set content-type and content-type of common file types in PHP_PHP tutorial

Use header to set content-type and content-type of common file types in php

Use header to set content-type and content-type of common file types in php

In PHP, you can send header information through the header function, and you can also set the content-type of the file. Here is a list of content-type values ​​for some common file types.



//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语法实现
// 
// override X-Powered-By: PHP: header('X-Powered-By: PHP/4.4.0'); header('X-Powered-By: Brain/0.6b'); //Document language header( 'Content-language: en'); //Tell the browser the last modified time $time = time() - 60; // or filemtime($fn), etc header('Last-Modified: '.gmdate('D , d M Y H:i:s', $time).' GMT'); //Tell the browser that the document content has not changed header('HTTP/1.1 304 Not Modified'); //Set the content length header('Content- Length: 1234'); //Set as a download type 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'); // Disable caching header('Cache-Control: no-cache, no-store, max-age for the current document =0, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Pragma: no-cache'); //Set content type : header('Content-Type: text/html; charset=iso-8859-1'); header('Content-Type: text/html; charset=utf-8'); header('Content-Type: text/ plain'); //Plain text format header('Content-Type: image/jpeg'); //JPG*** header('Content-Type: application/zip'); // ZIP file header('Content- Type: application/pdf'); // PDF file header('Content-Type: audio/mpeg'); // Audio file header('Content-Type: application/x-shockw**e-flash'); / /Flash animation//Display login dialog 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';

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1023582.htmlTechArticleUse header to set content-type and content-type of common file types in php. Use header to set content-type in php. And the content-type of common file types can be used in PHP through the header function...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何在 Windows 11 中更改网络类型为专用或公共如何在 Windows 11 中更改网络类型为专用或公共Aug 24, 2023 pm 12:37 PM

设置无线网络很常见,但选择或更改网络类型可能会令人困惑,尤其是在您不知道后果的情况下。如果您正在寻找有关如何在Windows11中将网络类型从公共更改为私有或反之亦然的建议,请继续阅读以获取一些有用的信息。Windows11中有哪些不同的网络配置文件?Windows11附带了许多网络配置文件,这些配置文件本质上是可用于配置各种网络连接的设置集。如果您在家中或办公室有多个连接,这将非常有用,因此您不必每次连接到新网络时都进行所有设置。专用和公用网络配置文件是Windows11中的两种常见类型,但通

用Python实现动态数组:从入门到精通用Python实现动态数组:从入门到精通Apr 21, 2023 pm 12:04 PM

Part1聊聊Python序列类型的本质在本博客中,我们来聊聊探讨Python的各种“序列”类,内置的三大常用数据结构——列表类(list)、元组类(tuple)和字符串类(str)的本质。不知道你发现没有,这些类都有一个很明显的共性,都可以用来保存多个数据元素,最主要的功能是:每个类都支持下标(索引)访问该序列的元素,比如使用语法Seq[i]​。其实上面每个类都是使用数组这种简单的数据结构表示。但是熟悉Python的读者可能知道这3种数据结构又有一些不同:比如元组和字符串是不能修改的,列表可以

视频矩阵账号怎么做?它的矩阵账号都有哪些类型呢?视频矩阵账号怎么做?它的矩阵账号都有哪些类型呢?Mar 21, 2024 pm 04:57 PM

随着短视频平台的盛行,视频矩阵账号营销已成为一种新兴营销方式。通过在不同平台上创建和管理多个账号,企业和个人能够实现品牌推广、粉丝增长和产品销售等目标。本文将为您探讨如何有效运用视频矩阵账号,并介绍不同类型的视频矩阵账号。一、视频矩阵账号怎么做?要想做好视频矩阵账号,需要遵循以下几个步骤:首先要明确你的视频矩阵账号的目标是什么,是为了品牌传播、粉丝增长还是产品销售。明确目标有助于制定相应的策略。2.选择平台:根据你的目标受众,选择合适的短视频平台。目前主流的短视频平台有抖音、快手、火山小视频等。

Golang 函数返回值的类型是什么?Golang 函数返回值的类型是什么?Apr 13, 2024 pm 05:42 PM

Go函数可以返回多个不同类型的值,返回值类型在函数签名中指定,并通过return语句返回。例如,函数可以返回一个整数和一个字符串:funcgetDetails()(int,string)。实战中,一个计算圆面积的函数可以返回面积和一个可选错误:funccircleArea(radiusfloat64)(float64,error)。注意事项:如果函数签名未指定类型,则返回空值;建议使用显式类型声明的return语句以提高可读性。

PHP编程中有哪些常见的模板引擎?PHP编程中有哪些常见的模板引擎?Jun 12, 2023 am 09:50 AM

最近几年,PHP编程中的模板引擎已经成为了PHP开发的重要组成部分,方便了程序员进行页面开发和管理。本文将介绍PHP编程中常见的模板引擎。SmartySmarty是一个比较常用的PHP模板引擎,它支持缓存模板、插件模块和自定义函数等一系列功能。Smarty的语法十分灵活,能够解决PHP变量与HTML标记的结合难题,使得PHP语言更适用于模板化的设计。而且,S

Python中类型提示的最佳实践Python中类型提示的最佳实践Apr 23, 2023 am 09:28 AM

使用动态语言一时爽,代码重构火葬场。相信你一定听过这句话,和单元测试一样,虽然写代码的时候花费你少量的时间,但是从长远来看,这是非常值得的。本文分享如何更好的理解和使用Python的类型提示。1、类型提示仅在语法层面有效类型提示(自PEP3107开始引入)用于向变量、参数、函数参数以及它们的返回值、类属性和方法添加类型。Python的变量类型是动态的,可以在运行时修改,为代码添加类型提示,仅在语法层面支持,对代码的运行没有任何影响,Python解释器在运行代码的时候会忽略类型提示。因此类型提

C++ 函数的类型和特性C++ 函数的类型和特性Apr 11, 2024 pm 03:30 PM

C++函数有以下类型:简单函数、const函数、静态函数、虚函数;特性包括:inline函数、默认参数、引用返回、重载函数。例如,calculateArea函数使用π计算给定半径圆的面积,并将其作为输出返回。

解析PHP8的新特性:如何利用属性的更强类型?解析PHP8的新特性:如何利用属性的更强类型?Sep 12, 2023 am 11:26 AM

解析PHP8的新特性:如何利用属性的更强类型?近年来,PHP在Web开发领域越来越受欢迎。它的灵活性和易学性使得PHP成为一种流行的编程语言,适用于各种项目。为了不断改进和优化语言,PHP8引入了许多新特性,其中包括属性的更强类型。在本文中,我们将深入探讨PHP8中属性类型的新特性,以及如何利用它们来提高代码的可靠性和性能。在PHP8之前,属性的类型声明可通

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),