$val ) { $this->mime_types[$key] = $temp_mime_types[$val]; } //flip the mime_type array to make the ext array $this->ext_types = array_flip($this->mime_types); } /** * function: getType * description: An alias to get_mimetype, * for backwards-compatibility with our old mimetype class. * * @param type $filename * @return type */ function getType($filename) { return $this->getMimetype($filename); } /** * function: get_mimetype * description: returns a mimetype associated with the * file extension of $filename * * @param type $filename * @param type $debug * @return string * mimetype associated with the file extension of $filename */ public function getMimetype($filename, $debug = FALSE) { //the file extension will be the last index in the exploded string $ext = @end(explode('.' , $filename)); $ext = strtolower($ext); //check the array for a predetermined mime type. If not found, add a warning //to the watch dog and use the system command to get a value if (!empty($this->mime_types[$ext])) { if (TRUE === $debug) { $return_type = $this->mime_types[$ext]; return array('mime_type' => $return_type, 'method' => 'from_array'); } return $this->mime_types[$ext]; } else { //this file was not in the drupal mime system. //add a line to the watchdog informing us of this incident $err_msg = 'Found a file extension not covered in the drupal mime func:'; watchdog('MimeClass', $err_msg . $ext ); } //by default return application octet stream if (TRUE == $debug) { return array('mime_type' => 'application/octet-stream', 'method' => 'last_resort'); } return 'application/octet-stream'; } /** * function: get_extension * description: returns *one* valid file extension for a given $mime_type * * @param type $mime_type * @param type $debug * @return type */ public function getExtension($type, $debug = FALSE) { if (!empty($this->ext_types[$type])) { if (TRUE == $debug) { return array('extension' => $this->ext_types[$type], 'method' => 'from_array'); } return $this->ext_types[$type]; } else{ //return bin by default... this could cause errors if handled incorrectly //and probably should return false or -1 or something to be handled //client side. if (TRUE == $debug) { return array('extension' => 'bin', 'method' => 'last_resort'); } return 'bin'; } } }