Comment on Partially incorrect MIME type detection for files newly uploaded to the cloud

<- View Parent
pepecyb@hub.hubzilla.hu@hub.hubzilla.hu ⁨6⁩ ⁨days⁩ ago
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:

    // 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.

original
Sort:hotnewtop