/** * Guess MIME Type based on the path of the file and it's content. * * @param string $path * @param string|resource $content * * @return string|null MIME Type or NULL if no extension detected */ public static function guessMimeType($path, $content) { $mimeType = MimeType::detectByContent($content); if (!(empty($mimeType) || in_array($mimeType, ['application/x-empty', 'text/plain', 'text/x-asm']))) { return $mimeType; } return MimeType::detectByFilename($path); }
/** * @inheritdoc */ public function getMimetype($path) { if (!($metadata = $this->getMetadata($path))) { return false; } $metadata['mimetype'] = MimeType::detectByFilename($path); return $metadata; }
/** * @inheritdoc */ public function getMimetype($path) { $location = $this->applyPathPrefix($path); $finfo = new Finfo(FILEINFO_MIME_TYPE); $mimetype = $finfo->file($location); if (in_array($mimetype, ['application/octet-stream', 'inode/x-empty'])) { $mimetype = Util\MimeType::detectByFilename($location); } return ['mimetype' => $mimetype]; }