Get image mime type

@param 	string	$pFile	Filename
@return 	string	Mime Type
@throws 	Exception
515714
private function _getImageMimeType($pFile = '') {
		if(PHPWord_Shared_File::file_exists($pFile)) {
			$image = getimagesize($pFile);
			return image_type_to_mime_type($image[2]);
		} else {
			throw new Exception("File $pFile does not exist");
		}
	}
673306
public function getPngType($filename = null)
    {
        $filename = $filename ? $filename : $this->pathToImage;

        $pngType = ord(file_get_contents($filename, false, null, 25, 1));

        if ($this->verbose) {
            $this->log("Checking png type of: " . $filename);
            $this->log($this->getPngTypeAsString($pngType));
        }

        return $pngType;
    }
126976
public function getMimeType(): string
    {
        $mimes = new MimeTypes();

        $type = $mimes->getMimeType($this->getAttribute('extension'));

        return $type ?? 'unknown';
    }
931798
public function getMimeType($filename)
    {
        $file_info = pathinfo($filename);
        $extension = isset($file_info['extension']) ? $file_info['extension'] : '';

        if (isset(self::$mimeTypeMap[$extension])) {
            $mime = self::$mimeTypeMap[$extension];
        } else {
            $finfo = finfo_open(FILEINFO_MIME_TYPE);
            $mime = finfo_file($finfo, $filename);
        }
        return $mime;
    }
1266607
protected function getMimeType($file)
    {
        $info = finfo_open(FILEINFO_MIME_TYPE);
        $mime = finfo_file($info, $file);
        finfo_close($info);

        return $mime;
    }
659801
public static function get(string $srcFile = ''): string
    {
        if (File::exists($srcFile) === false) {
            throw new RuntimeException('Source file does not exist: '.$srcFile);
        }

        $tmp = @\getimagesize($srcFile);
        if (empty($tmp)) {
            throw new RuntimeException('Invalid source file: '.$srcFile);
        }

        return \sprintf('%s:%s', $tmp[0], $tmp[1]);
    }
393753
private static function _guessType( $imageFile ){
        // Values from http://php.net/manual/en/image.constants.php starting with IMAGETYPE_GIF.
        // 0 - unknown,
        // 1 - GIF,
        // 2 - JPEG,
        // 3 - PNG
        // 15 - WBMP
        list($width, $height, $type) = getimagesize( $imageFile );

        unset($width, $height);

        if ( 1 == $type) {

            return ImageType::GIF;

        } else if ( 2 == $type) {

            return ImageType::JPEG;

        } else if ( 3 == $type) {

            return ImageType::PNG;

        } else if ( 15 == $type) {

            return ImageType::WBMP;

        }

        return ImageType::UNKNOWN;
    }
908480
private function validateImageMimeType()
    {
        $imageType = exif_imagetype($this->uploadFile->getTemporaryFilename());
        $mime = image_type_to_mime_type($imageType);
        if (!$imageType || !in_array($mime, parent::getAllowedMimeTypes())) {
            throw new \Exception("Uploaded image appears to be corrupt"); // @codeCoverageIgnore
        }
    }
338876
public function getMimeType()
    {
        if (function_exists('finfo_open')) {
            $finfo = finfo_open(FILEINFO_MIME);
            if (!$finfo) {
                throw new \RuntimeException('Failed to open finfo');
            }

            $actualInfo = @finfo_file($finfo, $this->getPathname());
            if (false === $actualInfo) {
                throw new \RuntimeException('Failed to read file info via finfo');
            }
            $mime = strtolower($actualInfo);
            finfo_close($finfo);

            if (!preg_match(
                '/^([a-z0-9]+\/[a-z0-9\-\.]+);\s+charset=(.*)$/', $mime, $matches
            )) {
                throw new \LogicException(
                    'An error parsing the MIME type "'.$mime.'".'
                );
            }

            return $matches[1];
        } elseif (function_exists('mime_content_type')) {
            return mime_content_type($this->getPathname());
        }

        throw new \RuntimeException(
            'The finfo extension or mime_content_type function are needed to '
            .'determine the Mime Type for this file.'
        );
    }
1243244
public static function getMimeType($file) {
    $defaultType = 'application/octet-stream';
    if (class_exists('\FileInfo')) {
      // use extension
      $fileInfo = new finfo(FILEINFO_MIME);
      $fileType = $fileInfo->file(file_get_contents($file));
    }
    else {
      // try detect image mime type
      $imageInfo = @getimagesize($file);
      $fileType = isset($imageInfo['mime']) ? $imageInfo['mime'] : '';
    }
    return (is_string($fileType) && !empty($fileType)) ? $fileType : $defaultType;
  }
881950
public function getMimeType(): string
	{
		if (!$this->isValid())
		{
			throw new UnsupportedActionException('File was not uploaded successfully, MIME type cannot be retrieved');
		}
		
		if ($this->type === null)
		{
			if (!extension_loaded('fileinfo'))
			{
				throw new UnsupportedActionException('Missing required extension: fileinfo');
			}
			
			$file = finfo_open(FILEINFO_MIME_TYPE);
			$this->type = finfo_file($file, $this->path);
			finfo_close($file);
		}
		
		return $this->type;
	}
510924
public static function getMimetype(string $file): string
    {
        $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
        $mimetype = finfo_file($finfo, $file);
        finfo_close($finfo);
        
        return $mimetype;
    }
960019
public static function getMimeType(string $file, bool $guess = true)
    {
        // Get mime using the file information functions
        if (function_exists('finfo_open')) {
            $info = finfo_open(FILEINFO_MIME_TYPE);

            $mime = finfo_file($info, $file);

            finfo_close($info);

            return $mime;

        } else {

            // Just guess mime by using the file extension
            if ($guess === true) {
                $mime_types = Filesystem::$mime_types;

                $extension = pathinfo($file, PATHINFO_EXTENSION);

                return isset($mime_types[$extension]) ? $mime_types[$extension] : false;
            } else {
                return false;
            }
        }
    }
94494
public static function typeFromMimetype($mime)
    {
        foreach (static::types() as $type => $mimetypes) {
            if (array_search($mime, $mimetypes) !== false) {
                return $type;
            }
        }
    }
1180997
public function mime()
    {
        if (!$this->exists()) {
            return false;
        }
        if (class_exists('finfo')) {
            $finfo = new finfo(FILEINFO_MIME);
            $type = $finfo->file($this->pwd());
            if (!$type) {
                return false;
            }
            list($type) = explode(';', $type);

            return $type;
        }
        if (function_exists('mime_content_type')) {
            return mime_content_type($this->pwd());
        }

        return false;
    }
231720
public function getMimeType()
    {
        // return mime type ala mimetype extension
        $finfo = finfo_open(FILEINFO_MIME);

        $mime = finfo_file($finfo, $this->getFullPath());

        return $mime;
    }
530227
public static function get_mime_type($filename) {
		if (extension_loaded('fileinfo')) {
			try {
				$finfo = new \finfo(FILEINFO_MIME_TYPE);
				return $finfo->file($filename);
			} catch (\Exception $e) {
				// Try next option...
			}
		}

		if (function_exists('mime_content_type')) {
			try {
				return mime_content_type($filename);
			} catch (\Exception $e) {
				// Try next option...
			}
		}

		$mime = \pdyn\filesystem\Mimetype::ext2mime(static::get_ext($filename));

		// Strip out encoding, if present.
		if (mb_strpos($mime, ';') !== false) {
			$mime = explode(';', $mime);
			$mime = $mime[0];
		}
		return $mime;
	}