Causes the error message "finfo::file(): Failed identify data 0:(null)"
in older libmagic/PHP versions, mostly in the ancient PHP 5.x tree.
self::$finfo = new \finfo(FILEINFO_MIME_TYPE);
}
- return self::$finfo->file($filename) ?: 'application/octet-stream';
+ // \finfo->file() can fail for files that contain only 1 byte, because libmagic expects at least
+ // a few bytes in order to determine the type. See https://bugs.php.net/bug.php?id=64684
+ $mimeType = @self::$finfo->file($filename);
+ return $mimeType ?: 'application/octet-stream';
}
/**