Comment on Partially incorrect MIME type detection for files newly uploaded to the cloud
I don’t see any chance of a fix for libmagic either. Particularly because the repository isn’t really very accessible.
My suggestion would be:
This is harmless, only affects CSS and should sort out the problem.
My suggestion would be:
// Until here we either used the provided mime type or set mimetype by extension.
// Both variants are inherently unsafe hence try to find and set the real mimetype before storage.
if (class_exists('finfo') && is_file($os_basepath . $os_relpath)) {
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mimetype = $finfo->file($os_basepath . $os_relpath);
if ($mimetype === false) {
$mimetype = 'application/octet-stream';
}
// Workaround for libmagic misidentifying CSS files as text/plain
if ($mimetype === 'text/plain' && preg_match('/\.css$/i', $os_relpath)) {
$mimetype = 'text/css';
}
}This is harmless, only affects CSS and should sort out the problem.
Sorry, but this won't work, as $os_rel_path is the hash, rather than the filename.
$filenameinstead of$os_relpath, soif ($mimetype === “text/plain” && preg_match(“/.css$/i”, $filename))Is that correct?
text/css.