A MIME type identifies the type of a file. When a server sends resources to a web browser it includes the MIME type of each file, and web browsers use that information to determine how to handle files. For instance, when a browser gets a file with the MIME type text/html it knows it needs to render it as HTML. Or, when it sees the image/jpeg type it knows the file is a JPG (or JPEG) image. For some types it might need to perform some specific magic. PDFs (application/pdf), for instance, are typically opened in the browser’s PDF viewer.
The media types standard is managed by IANA, and you can find a full list of MIME types on their website.
MIME types have a type, subtype and optional parameter:
On Linux servers you can check the MIME type using the file
utility with the --mime-type
option. Here are some examples:
$ file --mime-type index.html index.html: text/html $ file --mime-type index.php index.php: text/x-php $ file --mime-type robots.txt robots.txt: text/plain $ file --mime-type logo.jpg logo.jpg: image/jpeg $ file --mime-type backup.zip backup.zip: application/zip
The file
utility looks at the file itself to determine the MIME type. For binary files, such as images, it checks the signature (also called a magic number). For instance, PNG files use the hexadecimal value 89 50 4E 47 0D 0A 1A 0A as its signature. You can view the value with the xxd
utility:
$ xxd image.png | head -1 00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR $ file --mime-type image.png image.png: image/png
Plain text files don’t have a magic number. To check the file type it inspects the file itself.
One thing to be aware of is that file extensions have no meaning on Unix-like servers. File extensions exist purely for your convenience. It is perfectly fine to have, say, a PHP script without an extension – it doesn’t change the file’s MIME type. And you could give a PHP script and extension such as .txt or .png as well. In fact, this is sometimes the case when a website has been compromised – a malicious PHP script may be hiding as an innocent looking plain text or image file.
On cPanel servers you can see all existing MIME types via Advanced » MIME Types. You can’t change existing MIME types via the interface (they are managed at the server level). You do have the option to add a new MIME type. This can be useful if a new MIME type emerges that the server doesn’t know about yet. In practice, it is extremely unlikely this will happen. If you suspect a MIME type is missing, please contact us and we will add it if needed.