If you are attempting to get a file’s MIME type with your PHP installation for the first time, you may find that the MIME type always shows up as application/x-dpkg.

In this article, I will provide you with a fixed magic.mime file and show you what is happening.

When this happens

If you have PHP earlier than 5.3 installed on Windows (such as a WAMP server) and attempt to use mime.magic or the fileinfo extension to get file information.

Depending on your version of the magic.mime file, your may experience this issue. If you get your magic database separately from WAMP, from GnuWin32 for instance, it is already been formatted correctly. However, you wouldn’t be here if that was the case :).

Why this happens

PHP looks in your magic.mime file (which is a long list of mime types) for the correct MIME type. Windows gets hung up when an exclamation point appears at the front of the MIME type and stops there.

The first line that uses an exclamation point like this just so happens to be

0	string		!<arch>\ndebian application/x-dpkg

Download the fixed file

For magic.mime to work, you have to escape all starting exclamation points using backslashes. I already took care of that for you. You can download the file below. Simply swap yours with the Windows version or put it elsewhere and point to it in your finfo call.

Download magic.mime file for Windows and Linux

If this file helped you out, leave a comment!