Content-type_PHP tutorial for setting content-type and common file types with headers in php

Source: Internet
Author: User
Use the header in php to set the content-type and common file types. In php, you can use the header function to set content-type and common file types in content-typephp. in PHP, you can use the header function to set content-type and common file types. use header to set content-type and content-type of common file types
Use header in php to set content-type and content-type of common file types

In PHP, you can use the header function to send header information and set the content-type of the file. The following describes the content-type values of common file types.



// Author http://www.lai18.com // date 2015-06-22 // define the encoding header ('content-Type: text/html; charset = utf-8 '); // Atomheader ('content-type: application/atom + XML'); // CSSheader ('content-type: text/css '); // Javascriptheader ('content-type: text/javascript '); // JPEG Imageheader ('content-type: image/jpeg'); // JSONheader ('content-type: application/json'); // response header ('content-type: application/pdf '); // RSSheader ('content-Type: application/rss + xml; charset = ISO-8859-1 '); // Text (Plain) header ('content-type: text/plain'); // XMLheader ('content-type: text/XML '); // okheader ('http/1.1 200 OK '); // set a 404 header: header ('http/1.1 404 Not Found '); // Set the address to be Permanently redirected header ('http/1.1 301 Moved Permanently '); // go to a new address header ('Location: http://www.example.org /'); // File delay redirection: header ('refresh: 10; url = http://www.example.org/'); print 'You will be redirected in 10 seconds'; // of course, you can also use html syntax to implement //
// Override X-Powered-By: PHP: header ('x-Powered-By: PHP/4.4.0 '); header ('x-Powered-: brain/0.6b '); // The header of the document language ('content-language: en'); // notify the browser of the last modification 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 the header ('http/1.1 304 Not modified'); // set the Content Length header ('content-Length: 1234 '); // Set it to a download 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 the Cache 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'); // you can specify the 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 the login dialog box 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 ';

Using headers in php to set content-type and common file types, you can use the header function in PHP...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.