What does mime type mean in php

WBOY
Release: 2023-03-15 12:56:01
Original
3890 people have browsed it

In PHP, mime type is a multi-purpose Internet mail extension type. It is an Intel standard for describing message content types. It is designed to attach multimedia data when sending emails. PHP can use "mime_content_type ()" function to get the mime type of the file.

What does mime type mean in php

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

What does mime type mean in php

1. Definition of MIME

MIME (Multipurpose Internet Mail Extensions) multipurpose Internet mail extension type. It is an Internet standard for describing message content types

2. The original purpose of MIME design

MIME means Multifunctional Internet Mail Extensions. The original purpose of its design is to Attach multimedia data when sending an e-mail so that the mail client can process it according to its type. However, when it is supported by the HTTP protocol, its significance becomes even more significant. It makes HTTP transfer not only ordinary text, but also rich and colorful.

3.MIME file format

Each MIME type consists of two parts, a large category and a type.

For example:

Hypertext Markup Language text.html text/html

Normal text.txt text/plain

PDF document.pdf application/pdf

PNG image.png image/png

TAR file.tar application/x-tar

4.PHP gets the MIME type of the file

You can use the built-in function mime_content_type() function in PHP to obtain the mime type of the file.

Basic syntax:

string mime_content_type($file)

Parameters: The me_content_type() function accepts a single parameter $file, which specifies the file path of the MIME details to be found .

Return value: The me_content_type() function returns the MIME content type; if it fails, it will return false.

Example:

Let’s use the me_content_type() function to get the mime type of these files (the files are in the demo directory):

Implementation code:

<?php
# 输出不同类型文件的结果
echo mime_content_type(&#39;demo/1.docx&#39;) . "</br>";
echo mime_content_type(&#39;demo/1.html&#39;) . "</br>";
echo mime_content_type(&#39;demo/1.jpg&#39;) . "</br>";
echo mime_content_type(&#39;demo/1.pdf&#39;) . "</br>";
echo mime_content_type(&#39;demo/1.txt&#39;) . "</br>";
echo mime_content_type(&#39;demo/1.zip&#39;) . "</br>";
 ?>
Copy after login

Output result:

inode/x-empty

inode/x-empty

image/jpeg

application/pdf

inode/x-empty

application/zip

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What does mime type mean in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!