Get MIME type from file extension using PHP

This tutorial will show you how we you can get MIME type of a file. Most of the times we need to validate or check MIME type of a file when we upload a file for various reasons like security or validity check.

In this tutorial I have defined an array which holds almost all kinds of MIME type of files. So whenever you require to get the MIME type of a particular file then you can easily retrieve the MIME type of that file from this array.

PHP 5.4
MySQL 5.5
Apace http Server 2.4
Netbeans 7.4 (Optional)

Step 1. Creates a php projects using Netbeans or create a project directory under htdocs.

Step 2. Create a php file called config.php with the below source code in the project directory

Step 3. Create a mimes.php file with below source code in the project directory

Step 4. Usage of mimes array

That’s all. Thanks for reading.

Soumitra Roy Sarkar

I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on Twitter Facebook  Google Plus Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *