Exemple #1
0
 /**
  * Get MIME type for file
  *
  * @internal Used to get mime types
  * @param string &$file File path
  * @return string
  */
 private static function __getMIMEType(&$file)
 {
     $extension = \Craft\IOHelper::getMimeType($file);
     return !is_null($extension) ? $extension : 'application/octet-stream';
 }
Exemple #2
0
 /**
  * Get MIME type for file
  *
  * @internal Used to get mime types
  * @param string &$file File path
  * @return string
  */
 public static function __getMimeType(&$file)
 {
     $type = false;
     // Fileinfo documentation says fileinfo_open() will use the
     // MAGIC env var for the magic file
     if (extension_loaded('fileinfo') && isset($_ENV['MAGIC']) && ($finfo = finfo_open(FILEINFO_MIME, $_ENV['MAGIC'])) !== false) {
         if (($type = finfo_file($finfo, $file)) !== false) {
             // Remove the charset and grab the last content-type
             $type = explode(' ', str_replace('; charset=', ';charset=', $type));
             $type = array_pop($type);
             $type = explode(';', $type);
             $type = trim(array_shift($type));
         }
         finfo_close($finfo);
         // If anyone is still using mime_content_type()
     } elseif (function_exists('mime_content_type')) {
         $type = trim(mime_content_type($file));
     }
     if ($type !== false && strlen($type) > 0) {
         return $type;
     }
     // Otherwise do it the old fashioned way
     return \Craft\IOHelper::getMimeType($file);
 }