public function mime($file, $mime) { // If mime is calculated at upload, we have it already.. if ($mime) { return $mime; } // For older versions with no mime type, attempt to get mime type.. $e = substr(strrchr(strtolower($file), '.'), +1); $a = msDownload::browser(); $t = msDownload::mime_types(); // Check for PECL extension.. if (function_exists('finfo_file') && file_exists($file)) { $info = @finfo_open(FILEINFO_MIME_TYPE); $type = @finfo_file($info, $file); if ($type) { return $type; } } // Check mime array.. if (isset($t[$e])) { return $t[$e]; } // Fallback.. return in_array($a, array('IE', 'OPERA')) ? 'application/octetstream' : 'application/octet-stream'; }