/** * Figure out the MIME type of this medium * * @param string $user_path * @return string * @access public */ function getMimeType($user_type = null, $user_path = null) { if (empty($this->_mimetype)) { if (empty($user_path)) { global $mosConfig_absolute_path, $zoom; $user_path = $mosConfig_absolute_path . "/" . $zoom->_CONFIG['imagepath'] . $this->getDir() . "/" . $this->_filename; } //$this->_mimetype = MIME_Type::autoDetect($user_path, $user_type, $this->_type); if (!$this->_mimetype | empty($this->_mimetype)) { $ext = ereg_replace(".*\\.([^\\.]*)\$", "\\1", $this->_filename); $this->_mimetype = MIME_Helper::convertExtensionToMime($ext); } return $this->_mimetype; } else { return $this->_mimetype; } }
/** * Autodetect a file's MIME-type * * This function may be called staticly. * * @param string $file Path to the file to get the type of * @param string $custom_mime An optional custom 'default' value, mostly used for the filetype sent by the users' browser * @param bool $params Append MIME parameters if true * @return string $file's MIME-type on success, false boolean otherwise * @since 1.0.0beta1 * @static */ function autoDetect($file, $custom_mime = null, $custom_ext = null, $params = false) { if (function_exists('mime_content_type')) { $type = mime_content_type($file); if ($type == "application/octet-stream" || $type == "application/unknown") { if (!empty($custom_mime)) { $type = $custom_mime; } elseif (!empty($custom_ext)) { $type = MIME_Helper::convertExtensionToMime($custom_ext); } } } elseif (!empty($custom_mime)) { $type = $custom_mime; } else { $type = MIME_Type::_fileAutoDetect($file); } // _fileAutoDetect() may have returned an error. if ($type === false) { return $type; } //return PEAR::raiseError("Sorry, can't autodetect; you need the mime_magic extension or System_Command and 'file' installed to use this function."); if (!MIME_Helper::convertMimeToExtension($type)) { $type = MIME_Helper::convertExtensionToMime($custom_mime); } // flv (Flash Video format) files need exceptional handling (for now I'll provide a fictional mimetype) if ($custom_ext == "flv") { $type = "video/x-flv"; } // Don't return an empty string if (!$type || !strlen($type)) { //return PEAR::raiseError("Sorry, couldn't determine file type."); return false; } // Strip parameters if present & requested if (MIME_Type::hasParameters($type) && !$params) { $type = MIME_Type::stripParameters($type); } return $type; }