Correct way to detect mime type in php
What is the best and reliable way to detect mime type of a file in php? The following code which is suggested by many people failed to detect docx file mime type: $finfo = new finfo(FILEINFO_MIME_TYPE); $mime = $finfo->file($_FILES['file']['tmp_name']); echo $mime; exit; This is printing application/zip but it is supposed to be application/vnd.openxmlformats-officedocument.wordprocessingml.document h2ooooooo Based on this I've ported it to PHP: function getMicrosoftOfficeMimeInfo($file) { $fileInfo = array( 'word/' => array( 'type' => 'Microsoft Word 2007+', 'mime' => 'application/vnd