MIME type to file extensions

Here :

#0 DOWNLOAD (files extensions)

In the following notes the mapping between MIME types and file extensions.
Moreover files with this mapping downloadable.


The mime.types file maps Internet media types to unique file extensions.
Download mime.types file locally here or here (apache svn)
Download PHP arrary version of mapping from mime types to file extensions  locally here.
Download CSV(like) version of mapping from mime types to file extensions locally here

Note : in order to get mime type of a file using shell (by shell command) you can use file command
  file --mime-type <file-name>


Starting from file mime.types (download locally here) with the following 1 shell line:

(echo "$mime2ext = [" && grep -v "#" mime.types | awk '{print "t ""$1""=>""$2"","}' && echo """=>"undefine"];") >mime2extension.inc

we can get mapping (PHP) between mime type and file extensions :

The complete mapping file in PHP can be downloaded here.
If you preffer the mime type and file extensions mapping in CSV file:

grep -v "#"  mime.types | awk '{print $1","$2}' > mime2fileext.csv

Download CSV locally here.

#2 MIME (in a nutshell)

MIME (Multipurpose Internet Mail Extensions) is an internet standard and an email extension in order to allow :

  • Text in character sets other than ASCII
  • Non-text attachments: audio, video, images, application programs etc.
  • Message bodies with multiple parts
  • Header information in non-ASCII character sets

MIME is designed for SMTP but is also used outside of SMTP such as HTTP.

Example of MIME message :

MIME message example (client mail)

Download here original messagge .eml

From: Test From <testfrom@test123.xyz>
To:  Test To <testto@test123.xyz>
Subject: Very simple message
Email headers (image box a)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="stop-here"
MIME headers (boundary is start-here)
This is a multipart message in MIME format with 2 body parts.
This part is normally ignored (not displayed by clients).
This part is displayed by non-MIME compliant clients.
Preamble (not displayed by Mime clients)
Content-Type: text/plainthis is the body text
First message part (image box b). Type text/plain
Content-Type: text/plain;
Content-Disposition: attachment; filename="read.me"This readme is an attachment
Second message part (image box c). Type text/plain as attachment.
--stop-here-- MIME message end


 #2.1 MIME headers

  • MIME-Version
  • Content-Type
  • Content-Transfer-Encoding
  • Content-ID
  • Content-Description
  • Content-Disposition

Example (header):

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="stop-here"

The MIME header, in this simple example, reports :

Content-Type: multipart/mixed; -> there are parts that are separate by a special string
boundary="stop-here"           -> stop-here is the special string that delimit each part of the message

#2.2 Body Parts

Each body parts starts with -- followed by the boundary (--stop-here) and body part can contains itself the MIME header (Content-Type: text/plain;....). The last body part is defined by boundary followed by -- (--stop-here--)

Example :

This is a multipart message in MIME format with 2 body parts.

Content-Type: text/plain

this is the body text

Content-Type: text/plain;
Content-Disposition: attachment; filename="read.me"

This readme is an attachment



MIME type is a two-part (type and subtype) identifier for file formats. This provides information on wich type of native data is contained in the body (for example in order to select the right player or viewer).

Example :
Content-Type:  video/mpeg

  • video is the type (video data. Video requires the capability to display moving images, typically including specialized hardware and software.)
  • mpeg is the subtype (type of compression)

#3.1 How to get the mime type of a file from the command line?

With the command file
Example :

Busybook:Desktop busycrack$ file --mime-type note.txt
note.txt: text/plain
Busybook:Desktop busycrack$ file --mime-type b.png
b.png: image/png
Powered by WP Review