コード例 #1
1
 function getMime($file, $custom_type, $ext)
 {
     zmgimport('org.zoomfactory.lib.mime.zmgMime');
     return zmgMime::autoDetect($file, $custom_type, $ext);
 }
コード例 #2
-1
 /**
  * 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)
 {
     zmgimport('org.zoomfactory.lib.mime.zmgMimeHelper');
     $type = false;
     if (function_exists('finfo_open')) {
         // We have fileinfo
         $finfo = finfo_open(FILEINFO_MIME);
         $type = finfo_file($finfo, $file);
         finfo_close($finfo);
     } elseif (function_exists('mime_content_type')) {
         $type = mime_content_type($file);
         if (empty($type) && !empty($custom_ext)) {
             $type = zmgMimeHelper::convertExtensionToMime($custom_ext);
         }
     } elseif (!empty($custom_mime)) {
         $type = $custom_mime;
     } else {
         $type = zmgMime::_fileAutoDetect($file);
     }
     // _fileAutoDetect() may have returned an error.
     if ($type === false) {
         return $type;
     }
     if ($type == "application/octet-stream" || $type == "application/unknown") {
         if (!empty($custom_mime)) {
             $type = $custom_mime;
         } elseif (!empty($custom_ext)) {
             $type = zmgMimeHelper::convertExtensionToMime($custom_ext);
         }
     }
     if (!zmgMimeHelper::convertMimeToExtension($type)) {
         $type = zmgMimeHelper::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 zmgError::throwError("Sorry, couldn't determine file type.");
     }
     // Strip parameters if present & requested
     if (zmgMime::hasParameters($type) && !$params) {
         $type = zmgMime::stripParameters($type);
     }
     return $type;
 }