}
/**
- * detect mimetype based on both filename and content
- *
+ * detect mimetype only based on the content of file
* @param string $path
* @return string
+ * @since 18.0.0
*/
- public function detect($path) {
+ public function detectContent(string $path): string {
$this->loadMappings();
if (@is_dir($path)) {
return "httpd/unix-directory";
}
- $mimeType = $this->detectPath($path);
-
- if ($mimeType === 'application/octet-stream' and function_exists('finfo_open')
+ if (function_exists('finfo_open')
and function_exists('finfo_file') and $finfo = finfo_open(FILEINFO_MIME)
) {
$info = @strtolower(finfo_file($finfo, $path));
}
$isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://');
- if (!$isWrapped and $mimeType === 'application/octet-stream' && function_exists("mime_content_type")) {
+ if (!$isWrapped and function_exists("mime_content_type")) {
// use mime magic extension if available
$mimeType = mime_content_type($path);
}
return $mimeType;
}
+ /**
+ * detect mimetype based on both filename and content
+ *
+ * @param string $path
+ * @return string
+ */
+ public function detect($path) {
+ $mimeType = $this->detectPath($path);
+
+ if ($mimeType !== 'application/octet-stream') {
+ return $mimeType;
+ }
+
+ return $this->detectContent($path);
+ }
+
/**
* detect mimetype based on the content of a string
*
* @param string $path
* @return string
* @since 8.2.0
- **/
+ */
public function detectPath($path);
+ /**
+ * detect mimetype only based on the content of file
+ * @param string $path
+ * @return string
+ * @since 18.0.0
+ */
+ public function detectContent(string $path): string;
+
/**
* detect mimetype based on both filename and content
*