Set the content-type of common file types in php Headers

Source: Internet
Author: User

Set the content-type of common file types in php Headers

This article describes how to set content-type for common file types in php headers. For more information, see

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.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

// Date 2015-06-22

// Define the Encoding

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

 

// 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

// <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 ');

 

// Document Language

Header ('content-language: en ');

 

// Tell the browser 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

Header ('HTTP/1.1 304 Not modified ');

 

// Set the Content Length

Header ('content-Length: 1234 ');

 

// Set it to 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 for the current document

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

 

// Set 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 ';

The above is all the content of this article. I hope you will like it.

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.