The php Function Mime_Content_Type
When an application receives a file it must know what kind of file it is in order to interpret it correctly. To help in this task web servers and email clients make heavy use of MIME types - simple text strings that describe what kind of document they are sending or receiving.
The php function mime_content_type looks up the magic numbers in a large lookup table and finds out what type of file it is. This is very helpful because it saves time and memory to not have to look up each and every file extension individually.
Another reason to use this function is that some files obfuscate their code and the MIME type doesn't match the file suffix. Imagine if someone would obfuscate PHP code inside of a 'GIF' file and send it. The MIME type of the file might be image/jpeg but the file suffix is 'GIF'.
This php function is deprecated now and in PHP5 the PECL extension Fileinfo provides this functionality. It is a much better alternative as it is also available on shared linux hosts and doesn't require an undeclared variable error to work.
The finfo_file function will return an associative array with a mime_type key and a method key. The possible methods are fileinfo, mime_content_type, from_array, last_resort, and default. If one of the methods doesn't work it will fall back to using a generic MIME type which is application/octet-stream. The associative array contains the MIME type and a description of how it was found.