Spatie\MediaLibrary\Helpers\File::getMimetype PHP Method

getMimetype() public static method

* Get the mime type of a file.
public static getMimetype ( string $path ) : string
$path string
return string
    public static function getMimetype(string $path) : string
    {
        $finfo = new Finfo(FILEINFO_MIME_TYPE);
        return $finfo->file($path);
    }

Usage Example

 public function canConvert(Media $media) : bool
 {
     if (!$this->requirementsAreInstalled()) {
         return false;
     }
     if ($this->supportedExtensions()->contains(strtolower($media->extension))) {
         return true;
     }
     $urlGenerator = UrlGeneratorFactory::createForMedia($media);
     if (method_exists($urlGenerator, 'getPath') && file_exists($media->getPath()) && $this->supportedMimetypes()->contains(strtolower(File::getMimetype($media->getPath())))) {
         return true;
     }
     return false;
 }
All Usage Examples Of Spatie\MediaLibrary\Helpers\File::getMimetype