Tries to determine the correct mime type of the given file by using "magic numbers".

@return  array
482307
protected function checkFileType(): array
    {
        // Perform check
        if ($this->checkForBytes([0xFF, 0xD8, 0xFF])) {
            return [
                'ext'  => 'jpg',
                'mime' => 'image/jpeg'
            ];
        }

        if ($this->checkForBytes([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A])) {
            return [
                'ext'  => 'png',
                'mime' => 'image/png'
            ];
        }

        if ($this->checkForBytes([0x47, 0x49, 0x46])) {
            return [
                'ext'  => 'gif',
                'mime' => 'image/gif'
            ];
        }

        if ($this->checkForBytes([0x57, 0x45, 0x42, 0x50], 8)) {
            return [
                'ext'  => 'webp',
                'mime' => 'image/webp'
            ];
        }

        if ($this->checkForBytes([0x46, 0x4C, 0x49, 0x46])) {
            return [
                'ext'  => 'flif',
                'mime' => 'image/flif'
            ];
        }

        // Needs to be before `tif` check
        if ((
                $this->checkForBytes([0x49, 0x49, 0x2A, 0x0]) ||
                $this->checkForBytes([0x4D, 0x4D, 0x0, 0x2A])
            ) && $this->checkForBytes([0x43, 0x52], 8)
        ) {
            return [
                'ext'  => 'cr2',
                'mime' => 'image/x-canon-cr2'
            ];
        }

        if ($this->checkForBytes([0x49, 0x49, 0x2A, 0x0]) ||
            $this->checkForBytes([0x4D, 0x4D, 0x0, 0x2A])
        ) {
            return [
                'ext'  => 'tif',
                'mime' => 'image/tiff'
            ];
        }

        if ($this->checkForBytes([0x42, 0x4D])) {
            return [
                'ext'  => 'bmp',
                'mime' => 'image/bmp'
            ];
        }

        if ($this->checkForBytes([0x49, 0x49, 0xBC])) {
            return [
                'ext'  => 'jxr',
                'mime' => 'image/vnd.ms-photo'
            ];
        }

        if ($this->checkForBytes([0x38, 0x42, 0x50, 0x53])) {
            return [
                'ext'  => 'psd',
                'mime' => 'image/vnd.adobe.photoshop'
            ];
        }

        // Zip-based file formats
        // Need to be before the `zip` check
        if ($this->checkForBytes([0x50, 0x4B, 0x3, 0x4])) {
            if ($this->checkForBytes([
                0x6D, 0x69, 0x6D, 0x65, 0x74, 0x79, 0x70,
                0x65, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63,
                0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x65,
                0x70, 0x75, 0x62, 0x2B, 0x7A, 0x69, 0x70
            ], 30)) {
                return [
                    'ext'  => 'epub',
                    'mime' => 'application/epub+zip'
                ];
            }

            // Assumes signed `.xpi` from addons.mozilla.org
            if ($this->checkString('META-INF/mozilla.rsa', 30)) {
                return [
                    'ext'  => 'xpi',
                    'mime' => 'application/x-xpinstall'
                ];
            }

            if ($this->checkString('mimetypeapplication/vnd.oasis.opendocument.text', 30)) {
                return [
                    'ext'  => 'odt',
                    'mime' => 'application/vnd.oasis.opendocument.text'
                ];
            }

            if ($this->checkString('mimetypeapplication/vnd.oasis.opendocument.spreadsheet', 30)) {
                return [
                    'ext'  => 'ods',
                    'mime' => 'application/vnd.oasis.opendocument.spreadsheet'
                ];
            }

            if ($this->checkString('mimetypeapplication/vnd.oasis.opendocument.presentation', 30)) {
                return [
                    'ext'  => 'odp',
                    'mime' => 'application/vnd.oasis.opendocument.presentation'
                ];
            }

            // The docx, xlsx and pptx file types extend the Office Open XML file format:
            // https://en.wikipedia.org/wiki/Office_Open_XML_file_formats
            $zipHeaderIndex = 0; // The first zip header was already found at index 0
            $oxmlFound = false;
            $type = null;
            $oxmlCTypes = $this->toBytes('[Content_Types].xml');
            $oxmlRels = $this->toBytes('_rels/.rels');

            do {
                $offset = $zipHeaderIndex + 30;

                if (!$oxmlFound) {
                    $oxmlFound = $this->checkForBytes($oxmlCTypes, $offset) || $this->checkForBytes($oxmlRels, $offset);
                }

                if (!$type) {
                    if ($this->checkString('word/', $offset)) {
                        $type = [
                            'ext'  => 'docx',
                            'mime' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
                        ];
                    } elseif ($this->checkString('ppt/', $offset)) {
                        $type = [
                            'ext'  => 'pptx',
                            'mime' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
                        ];
                    } elseif ($this->checkString('xl/', $offset)) {
                        $type = [
                            'ext'  => 'xlsx',
                            'mime' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
                        ];
                    }
                }

                if ($oxmlFound && $type) {
                    return $type;
                }

                $zipHeaderIndex = $this->searchForBytes([0x50, 0x4B, 0x03, 0x04], $offset);
            } while ($zipHeaderIndex !== -1);

            // No more zip parts available in the buffer, but maybe we are almost certain about the type?
            if ($type) {
                return $type;
            }

            return [
                'ext'  => 'zip',
                'mime' => 'application/zip'
            ];
        }

        if ($this->checkForBytes([0x75, 0x73, 0x74, 0x61, 0x72], 257)) {
            return [
                'ext'  => 'tar',
                'mime' => 'application/x-tar'
            ];
        }

        if ($this->checkForBytes([0x52, 0x61, 0x72, 0x21, 0x1A, 0x7]) &&
            (
                $this->byteCache[6] === 0x0 ||
                $this->byteCache[6] === 0x1
            )
        ) {
            return [
                'ext'  => 'rar',
                'mime' => 'application/x-rar-compressed'
            ];
        }

        if ($this->checkForBytes([0x1F, 0x8B, 0x8])) {
            return [
                'ext'  => 'gz',
                'mime' => 'application/gzip'
            ];
        }

        if ($this->checkForBytes([0x42, 0x5A, 0x68])) {
            return [
                'ext'  => 'bz2',
                'mime' => 'application/x-bzip2'
            ];
        }

        if ($this->checkForBytes([0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C])) {
            return [
                'ext'  => '7z',
                'mime' => 'application/x-7z-compressed'
            ];
        }

        if ($this->checkForBytes([0x78, 0x01])) {
            return [
                'ext'  => 'dmg',
                'mime' => 'application/x-apple-diskimage'
            ];
        }

        if ($this->checkForBytes([0x33, 0x67, 0x70, 0x35]) || // 3gp5
            (
                $this->checkForBytes([0x0, 0x0, 0x0]) &&
                $this->checkForBytes([0x66, 0x74, 0x79, 0x70], 4) &&
                (
                    $this->checkForBytes([0x6D, 0x70, 0x34, 0x31], 8) || // MP41
                    $this->checkForBytes([0x6D, 0x70, 0x34, 0x32], 8) || // MP42
                    $this->checkForBytes([0x69, 0x73, 0x6F, 0x6D], 8) || // ISOM
                    $this->checkForBytes([0x69, 0x73, 0x6F, 0x32], 8) || // ISO2
                    $this->checkForBytes([0x6D, 0x6D, 0x70, 0x34], 8) || // MMP4
                    $this->checkForBytes([0x4D, 0x34, 0x56], 8) || // M4V
                    $this->checkForBytes([0x64, 0x61, 0x73, 0x68], 8) // DASH
                )
            )
        ) {
            return [
                'ext'  => 'mp4',
                'mime' => 'video/mp4'
            ];
        }

        if ($this->checkForBytes([0x4D, 0x54, 0x68, 0x64])) {
            return [
                'ext'  => 'mid',
                'mime' => 'audio/midi'
            ];
        }

        // https://github.com/threatstack/libmagic/blob/master/magic/Magdir/matroska
        if ($this->checkForBytes([0x1A, 0x45, 0xDF, 0xA3])) {
            $idPos = $this->searchForBytes([0x42, 0x82]);

            if ($idPos !== -1) {
                if ($this->checkString('matroska', $idPos + 3)) {
                    return [
                        'ext'  => 'mkv',
                        'mime' => 'video/x-matroska'
                    ];
                }

                if ($this->checkString('webm', $idPos + 3)) {
                    return [
                        'ext'  => 'webm',
                        'mime' => 'video/webm'
                    ];
                }
            }
        }

        if ($this->checkForBytes([0x0, 0x0, 0x0, 0x14, 0x66, 0x74, 0x79, 0x70, 0x71, 0x74, 0x20, 0x20]) ||
            $this->checkForBytes([0x66, 0x72, 0x65, 0x65], 4) ||
            $this->checkForBytes([0x66, 0x74, 0x79, 0x70, 0x71, 0x74, 0x20, 0x20], 4) ||
            $this->checkForBytes([0x6D, 0x64, 0x61, 0x74], 4) || // MJPEG
            $this->checkForBytes([0x6D, 0x6F, 0x6F, 0x76], 4) || // Moov
            $this->checkForBytes([0x77, 0x69, 0x64, 0x65], 4)
        ) {
            return [
                'ext'  => 'mov',
                'mime' => 'video/quicktime'
            ];
        }

        // RIFF file format which might be AVI, WAV, QCP, etc
        if ($this->checkForBytes([0x52, 0x49, 0x46, 0x46])) {
            if ($this->checkForBytes([0x41, 0x56, 0x49], 8)) {
                return [
                    'ext'  => 'avi',
                    'mime' => 'video/vnd.avi'
                ];
            }

            if ($this->checkForBytes([0x57, 0x41, 0x56, 0x45], 8)) {
                return [
                    'ext'  => 'wav',
                    'mime' => 'audio/vnd.wave'
                ];
            }

            // QLCM, QCP file
            if ($this->checkForBytes([0x51, 0x4C, 0x43, 0x4D], 8)) {
                return [
                    'ext'  => 'qcp',
                    'mime' => 'audio/qcelp'
                ];
            }

            // animated cursors
            // mime type might be wrong, but there's not much information about the "correct" one
            if ($this->checkForBytes([0x41, 0x43, 0x4F, 0x4E], 8)) {
                return [
                    'ext'  => 'ani',
                    'mime' => 'application/x-navi-animation'
                ];
            }
        }

        if ($this->checkForBytes([0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9])) {
            return [
                'ext'  => 'wmv',
                'mime' => 'video/x-ms-wmv'
            ];
        }

        if ($this->checkForBytes([0x0, 0x0, 0x1, 0xBA]) || $this->checkForBytes([0x0, 0x0, 0x1, 0xB3])) {
            return [
                'ext'  => 'mpg',
                'mime' => 'video/mpeg'
            ];
        }

        if ($this->checkForBytes([0x66, 0x74, 0x79, 0x70, 0x33, 0x67], 4)) {
            return [
                'ext'  => '3gp',
                'mime' => 'video/3gpp'
            ];
        }

        // Check for MPEG header at different starting offsets
        for ($offset = 0; ($offset < 2 && $offset < ($this->byteCacheLen - 16)); $offset++) {
            if ($this->checkForBytes([0x49, 0x44, 0x33], $offset) || // ID3 header
                $this->checkForBytes([0xFF, 0xE2], $offset, [0xFF, 0xE2]) // MPEG 1 or 2 Layer 3 header
            ) {
                return [
                    'ext'  => 'mp3',
                    'mime' => 'audio/mpeg'
                ];
            }

            // MPEG 1 or 2 Layer 2 header
            if ($this->checkForBytes([0xFF, 0xE4], $offset, [0xFF, 0xE4])) {
                return [
                    'ext'  => 'mp2',
                    'mime' => 'audio/mpeg'
                ];
            }

            // MPEG 2 layer 0 using ADTS
            if ($this->checkForBytes([0xFF, 0xF8], $offset, [0xFF, 0xFC])) {
                return [
                    'ext'  => 'mp2',
                    'mime' => 'audio/mpeg'
                ];
            }

            // MPEG 4 layer 0 using ADTS
            if ($this->checkForBytes([0xFF, 0xF0], $offset, [0xFF, 0xFC])) {
                return [
                    'ext'  => 'mp4',
                    'mime' => 'audio/mpeg'
                ];
            }
        }

        if ($this->checkForBytes([0x66, 0x74, 0x79, 0x70, 0x4D, 0x34, 0x41], 4) ||
            $this->checkForBytes([0x4D, 0x34, 0x41, 0x20])
        ) {
            return [ // MPEG-4 layer 3 (audio)
                'ext'  => 'm4a',
                'mime' => 'audio/mp4' // RFC 4337
            ];
        }

        // Needs to be before `ogg` check
        if ($this->checkForBytes([0x4F, 0x70, 0x75, 0x73, 0x48, 0x65, 0x61, 0x64], 28)) {
            return [
                'ext'  => 'opus',
                'mime' => 'audio/opus'
            ];
        }

        // If 'OggS' in first  bytes, then OGG container
        if ($this->checkForBytes([0x4F, 0x67, 0x67, 0x53])) {
            // This is a OGG container

            // If ' theora' in header.
            if ($this->checkForBytes([0x80, 0x74, 0x68, 0x65, 0x6F, 0x72, 0x61], 28)) {
                return [
                    'ext'  => 'ogv',
                    'mime' => 'video/ogg'
                ];
            }

            // If '\x01video' in header.
            if ($this->checkForBytes([0x01, 0x76, 0x69, 0x64, 0x65, 0x6F, 0x00], 28)) {
                return [
                    'ext'  => 'ogm',
                    'mime' => 'video/ogg'
                ];
            }

            // If ' FLAC' in header  https://xiph.org/flac/faq.html
            if ($this->checkForBytes([0x7F, 0x46, 0x4C, 0x41, 0x43], 28)) {
                return [
                    'ext'  => 'oga',
                    'mime' => 'audio/ogg'
                ];
            }

            // 'Speex  ' in header https://en.wikipedia.org/wiki/Speex
            if ($this->checkForBytes([0x53, 0x70, 0x65, 0x65, 0x78, 0x20, 0x20], 28)) {
                return [
                    'ext'  => 'spx',
                    'mime' => 'audio/ogg'
                ];
            }

            // If '\x01vorbis' in header
            if ($this->checkForBytes([0x01, 0x76, 0x6F, 0x72, 0x62, 0x69, 0x73], 28)) {
                return [
                    'ext'  => 'ogg',
                    'mime' => 'audio/ogg'
                ];
            }

            // Default OGG container https://www.iana.org/assignments/media-types/application/ogg
            // @codeCoverageIgnoreStart
            return [
                'ext'  => 'ogx',
                'mime' => 'application/ogg'
            ];
            // @codeCoverageIgnoreEnd
        }

        if ($this->checkForBytes([0x66, 0x4C, 0x61, 0x43])) {
            return [
                'ext'  => 'flac',
                'mime' => 'audio/x-flac'
            ];
        }

        // 'MAC '
        if ($this->checkForBytes([0x4D, 0x41, 0x43, 0x20])) {
            return [
                'ext'  => 'ape',
                'mime' => 'audio/ape'
            ];
        }

        // 'wvpk'
        if ($this->checkForBytes([0x77, 0x76, 0x70, 0x6B])) {
            return [
                'ext'  => 'wv',
                'mime' => 'audio/wavpack'
            ];
        }

        if ($this->checkForBytes([0x23, 0x21, 0x41, 0x4D, 0x52, 0x0A])) {
            return [
                'ext'  => 'amr',
                'mime' => 'audio/amr'
            ];
        }

        if ($this->checkForBytes([0x25, 0x50, 0x44, 0x46])) {
            return [
                'ext'  => 'pdf',
                'mime' => 'application/pdf'
            ];
        }

        if ($this->checkForBytes([0x4D, 0x5A])) {
            return [
                'ext'  => 'exe',
                'mime' => 'application/x-msdownload'
            ];
        }

        if ((
                $this->byteCache[0] === 0x43 || $this->byteCache[0] === 0x46
            ) &&
            $this->checkForBytes([0x57, 0x53], 1)
        ) {
            return [
                'ext'  => 'swf',
                'mime' => 'application/x-shockwave-flash'
            ];
        }

        if ($this->checkForBytes([0x7B, 0x5C, 0x72, 0x74, 0x66])) {
            return [
                'ext'  => 'rtf',
                'mime' => 'application/rtf'
            ];
        }

        if ($this->checkForBytes([0x00, 0x61, 0x73, 0x6D])) {
            return [
                'ext'  => 'wasm',
                'mime' => 'application/wasm'
            ];
        }

        if ($this->checkForBytes([0x77, 0x4F, 0x46]) &&
            (
                $this->checkForBytes([0x00, 0x01, 0x00, 0x00], 4) ||
                $this->checkForBytes([0x4F, 0x54, 0x54, 0x4F], 4)
            )
        ) {
            if ($this->byteCache[3] === 0x46) {
                return [
                    'ext'  => 'woff',
                    'mime' => 'font/woff'
                ];
            }

            if ($this->byteCache[3] === 0x32) {
                return [
                    'ext'  => 'woff2',
                    'mime' => 'font/woff2'
                ];
            }
        }

        if ($this->checkForBytes([0x4C, 0x50], 34) &&
            (
                $this->checkForBytes([0x00, 0x00, 0x01], 8) ||
                $this->checkForBytes([0x01, 0x00, 0x02], 8) ||
                $this->checkForBytes([0x02, 0x00, 0x02], 8)
            )
        ) {
            return [
                'ext'  => 'eot',
                'mime' => 'application/vnd.ms-fontobject'
            ];
        }

        if ($this->checkForBytes([0x00, 0x01, 0x00, 0x00, 0x00])) {
            return [
                'ext'  => 'ttf',
                'mime' => 'font/ttf'
            ];
        }

        if ($this->checkForBytes([0x4F, 0x54, 0x54, 0x4F, 0x00])) {
            return [
                'ext'  => 'otf',
                'mime' => 'font/otf'
            ];
        }

        if ($this->checkForBytes([0x00, 0x00, 0x01, 0x00])) {
            return [
                'ext'  => 'ico',
                'mime' => 'image/x-icon'
            ];
        }

        if ($this->checkForBytes([0x00, 0x00, 0x02, 0x00])) {
            return [
                'ext'  => 'cur',
                'mime' => 'image/x-icon'
            ];
        }

        if ($this->checkForBytes([0x46, 0x4C, 0x56, 0x01])) {
            return [
                'ext'  => 'flv',
                'mime' => 'video/x-flv'
            ];
        }

        if ($this->checkForBytes([0x25, 0x21])) {
            return [
                'ext'  => 'ps',
                'mime' => 'application/postscript'
            ];
        }

        if ($this->checkForBytes([0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00])) {
            return [
                'ext'  => 'xz',
                'mime' => 'application/x-xz'
            ];
        }

        if ($this->checkForBytes([0x53, 0x51, 0x4C, 0x69])) {
            return [
                'ext'  => 'sqlite',
                'mime' => 'application/x-sqlite3'
            ];
        }

        if ($this->checkForBytes([0x4E, 0x45, 0x53, 0x1A])) {
            return [
                'ext'  => 'nes',
                'mime' => 'application/x-nintendo-nes-rom'
            ];
        }

        if ($this->checkForBytes([0x43, 0x72, 0x32, 0x34])) {
            return [
                'ext'  => 'crx',
                'mime' => 'application/x-google-chrome-extension'
            ];
        }

        if ($this->checkForBytes([0x4D, 0x53, 0x43, 0x46]) ||
            $this->checkForBytes([0x49, 0x53, 0x63, 0x28])
        ) {
            return [
                'ext'  => 'cab',
                'mime' => 'application/vnd.ms-cab-compressed'
            ];
        }

        // Needs to be before `ar` check
        if ($this->checkForBytes([
            0x21, 0x3C, 0x61, 0x72, 0x63, 0x68, 0x3E,
            0x0A, 0x64, 0x65, 0x62, 0x69, 0x61, 0x6E,
            0x2D, 0x62, 0x69, 0x6E, 0x61, 0x72, 0x79
        ])) {
            return [
                'ext'  => 'deb',
                'mime' => 'application/x-deb'
            ];
        }

        if ($this->checkForBytes([0x21, 0x3C, 0x61, 0x72, 0x63, 0x68, 0x3E])) {
            return [
                'ext'  => 'ar',
                'mime' => 'application/x-unix-archive'
            ];
        }

        if ($this->checkForBytes([0xED, 0xAB, 0xEE, 0xDB])) {
            return [
                'ext'  => 'rpm',
                'mime' => 'application/x-rpm'
            ];
        }

        if ($this->checkForBytes([0x1F, 0xA0]) || $this->checkForBytes([0x1F, 0x9D])) {
            return [
                'ext'  => 'z',
                'mime' => 'application/x-compress'
            ];
        }

        if ($this->checkForBytes([0x4C, 0x5A, 0x49, 0x50])) {
            return [
                'ext'  => 'lz',
                'mime' => 'application/x-lzip'
            ];
        }

        if ($this->checkForBytes([0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1])) {
            // MS Visio
            if ($this->checkForBytes([
                0x56, 0x00, 0x69, 0x00, 0x73,
                0x00, 0x69, 0x00, 0x6F, 0x00,
                0x44, 0x00, 0x6F, 0x00, 0x63
            ], 1664)) {
                return [
                    'ext'  => 'vsd',
                    'mime' => 'application/vnd.visio'
                ];
            }

            return [
                'ext'  => 'msi',
                'mime' => 'application/x-msi'
            ];
        }

        if ($this->checkForBytes([
            0x06, 0x0E, 0x2B, 0x34, 0x02, 0x05, 0x01,
            0x01, 0x0D, 0x01, 0x02, 0x01, 0x01, 0x02
        ])) {
            return [
                'ext'  => 'mxf',
                'mime' => 'application/mxf'
            ];
        }

        if ($this->checkForBytes([0x47], 4) &&
            (
                $this->checkForBytes([0x47], 192) ||
                $this->checkForBytes([0x47], 196)
            )
        ) {
            return [
                'ext'  => 'mts',
                'mime' => 'video/mp2t'
            ];
        }

        if ($this->checkForBytes([0x42, 0x4C, 0x45, 0x4E, 0x44, 0x45, 0x52])) {
            return [
                'ext'  => 'blend',
                'mime' => 'application/x-blender'
            ];
        }

        if ($this->checkForBytes([0x42, 0x50, 0x47, 0xFB])) {
            return [
                'ext'  => 'bpg',
                'mime' => 'image/bpg'
            ];
        }

        if ($this->checkForBytes([0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A])) {
            // JPEG-2000 family
            if ($this->checkForBytes([0x6A, 0x70, 0x32, 0x20], 20)) {
                return [
                    'ext'  => 'jp2',
                    'mime' => 'image/jp2'
                ];
            }

            if ($this->checkForBytes([0x6A, 0x70, 0x78, 0x20], 20)) {
                return [
                    'ext'  => 'jpx',
                    'mime' => 'image/jpx'
                ];
            }

            if ($this->checkForBytes([0x6A, 0x70, 0x6D, 0x20], 20)) {
                return [
                    'ext'  => 'jpm',
                    'mime' => 'image/jpm'
                ];
            }

            if ($this->checkForBytes([0x6D, 0x6A, 0x70, 0x32], 20)) {
                return [
                    'ext'  => 'mj2',
                    'mime' => 'image/mj2'
                ];
            }
        }

        if ($this->checkForBytes([0x46, 0x4F, 0x52, 0x4D, 0x00])) {
            return [
                'ext'  => 'aif',
                'mime' => 'audio/aiff'
            ];
        }

        if ($this->checkForBytes([0x42, 0x4F, 0x4F, 0x4B, 0x4D, 0x4F, 0x42, 0x49], 60)) {
            return [
                'ext'  => 'mobi',
                'mime' => 'application/x-mobipocket-ebook'
            ];
        }

        // File Type Box (https://en.wikipedia.org/wiki/ISO_base_media_file_format)
        if ($this->checkForBytes([0x66, 0x74, 0x79, 0x70], 4)) {
            if ($this->checkForBytes([0x6D, 0x69, 0x66, 0x31], 8)) {
                return [
                    'ext'  => 'heic',
                    'mime' => 'image/heif'
                ];
            }

            if ($this->checkForBytes([0x6D, 0x73, 0x66, 0x31], 8)) {
                return [
                    'ext'  => 'heic',
                    'mime' => 'image/heif-sequence'
                ];
            }

            if ($this->checkForBytes([0x68, 0x65, 0x69, 0x63], 8) ||
                $this->checkForBytes([0x68, 0x65, 0x69, 0x78], 8)
            ) {
                return [
                    'ext'  => 'heic',
                    'mime' => 'image/heic'
                ];
            }

            // @codeCoverageIgnoreStart
            if ($this->checkForBytes([0x68, 0x65, 0x76, 0x63], 8) ||
                $this->checkForBytes([0x68, 0x65, 0x76, 0x78], 8)
            ) {
                return [
                    'ext'  => 'heic',
                    'mime' => 'image/heic-sequence'
                ];
            }
            // @codeCoverageIgnoreEnd
        }

        if ($this->checkForBytes([0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A])) {
            return [
                'ext'  => 'ktx',
                'mime' => 'image/ktx'
            ];
        }

        if ($this->checkForBytes([0x44, 0x49, 0x43, 0x4D], 128)) {
            return [
                'ext'  => 'dcm',
                'mime' => 'application/dicom'
            ];
        }

        if ($this->checkForBytes([0x1B, 0x4C, 0x75, 0x61])) {
            return [
                'ext'  => 'luac',
                'mime' => 'application/x-lua-bytecode'
            ];
        }

        if ($this->checkForBytes([0x64, 0x6E, 0x73, 0x2E]) || $this->checkForBytes([0x2E, 0x73, 0x6E, 0x64])) {
            return [
                'ext'  => 'au',
                'mime' => 'audio/basic'
            ];
        }

        // unfortunately, these formats don't have a proper mime type, but they are worth detecting
        if ($this->checkForBytes([0x67, 0x33, 0x64, 0x72, 0x65, 0x6D])) {
            return [
                'ext'  => 'g3drem',
                'mime' => 'application/octet-stream'
            ];
        }

        if ($this->checkForBytes([0x73, 0x69, 0x6c, 0x68, 0x6f, 0x75, 0x65, 0x74, 0x74, 0x65, 0x30, 0x35])) {
            return [
                'ext'  => 'studio3',
                'mime' => 'application/octet-stream'
            ];
        }

        // this class is intended to detect binary files, only. But there's nothing wrong in
        // trying to detect text files aswell.
        if ($this->checkString('<?xml ')) {
            if ($this->searchForBytes($this->toBytes('<!doctype svg'), 6) !== -1 ||
                $this->searchForBytes($this->toBytes('<!DOCTYPE svg'), 6) !== -1 ||
                $this->searchForBytes($this->toBytes('<svg'), 6) !== -1
            ) {
                return [
                    'ext'  => 'svg',
                    'mime' => 'image/svg+xml'
                ];
            }

            if ($this->searchForBytes($this->toBytes('<!doctype html'), 6) !== -1 ||
                $this->searchForBytes($this->toBytes('<!DOCTYPE html'), 6) !== -1 ||
                $this->searchForBytes($this->toBytes('<html'), 6) !== -1
            ) {
                return [
                    'ext'  => 'html',
                    'mime' => 'text/html'
                ];
            }

            if ($this->searchForBytes($this->toBytes('<rdf:RDF'), 6) !== -1) {
                return [
                    'ext'  => 'rdf',
                    'mime' => 'application/rdf+xml'
                ];
            }

            if ($this->searchForBytes($this->toBytes('<rss version="2.0"'), 6) !== -1) {
                return [
                    'ext'  => 'rss',
                    'mime' => 'application/rss+xml'
                ];
            }

            return [
                'ext'  => 'xml',
                'mime' => 'application/xml'
            ];
        }

        if ($this->checkString('<!doctype html') ||
            $this->checkString('<!DOCTYPE html') ||
            $this->checkString('<html')
        ) {
            return [
                'ext'  => 'html',
                'mime' => 'text/html'
            ];
        }

        return [];
    }
235558
public function getMime()
    {
        if ($this->exists()) {
            $finfo = new \finfo(FILEINFO_MIME | FILEINFO_PRESERVE_ATIME);
            $mime = $finfo->file($this->getRealPath());
            return $mime;
        }
        return null;
    }
763282
public function getMimeType()
    {
        $mimetypeRepo = new PhpRepository();
        $path = $this->getPathFilename();

        return $mimetypeRepo->findType(pathinfo($path, PATHINFO_EXTENSION)) ?: 'application/octet-stream';
    }
36397
public function dataType()
    {
        $fileInfo = new finfo( FILEINFO_MIME_TYPE | FILEINFO_SYMLINK );
        $mimeType = $fileInfo->file( $this->filePath );
        eZDebugSetting::writeDebug( 'kernel-clustering', $mimeType, "fs::dataType( {$this->filePath} )" );
        return $mimeType ?: null;
    }
510924
public static function getMimetype(string $file): string
    {
        $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
        $mimetype = finfo_file($finfo, $file);
        finfo_close($finfo);
        
        return $mimetype;
    }
903096
protected function validateExtensionAndMimeType()
    {
        if ($this->allowed_file_extensions == null && ($this->file_extensions_mime_types == null || empty($this->file_extensions_mime_types))) {
            // it is not set to limit uploaded file extensions and mime types.
            return true;
        }

        // get only file extension of uploaded file.
        $file_name_explode = explode('.', $this->files[$this->input_file_name]['name']);
        if (!is_array($file_name_explode)) {
            unset($file_name_explode);
            $this->setErrorMessage(
                sprintf(static::__('Unable to validate extension for the file %s.'), $this->files[$this->input_file_name]['name']),
                'RDU_UNABLE_VALIDATE_EXT',
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['size'],
                $this->files[$this->input_file_name]['type']
            );
            return false;
        }
        $file_extension = strtolower($file_name_explode[count($file_name_explode)-1]);
        unset($file_name_explode);

        // validate allowed extensions.
        if (is_array($this->allowed_file_extensions) && !in_array($file_extension, $this->allowed_file_extensions)) {
            unset($file_extension);
            $this->setErrorMessage(
                sprintf(static::__('You have uploaded the file that is not allowed extension. (%s)'), $this->files[$this->input_file_name]['name']),
                'RDU_NOT_ALLOW_EXT',
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['size'],
                $this->files[$this->input_file_name]['type']
            );
            return false;
        }

        // validate allowed mime types that match uploaded file's extension.
        if (is_array($this->file_extensions_mime_types) && !empty($this->file_extensions_mime_types)) {
            if (!array_key_exists($file_extension, $this->file_extensions_mime_types)) {
                unset($file_extension);
                $this->setErrorMessage(
                    sprintf(static::__('Unable to validate the file extension and mime type. (%s). This file extension was not set in the &quot;file_extensions_mime_types&quot; property.'), $this->files[$this->input_file_name]['name']),
                    'RDU_UNABLE_VALIDATE_EXT_AND_MIME',
                    $this->files[$this->input_file_name]['name'],
                    $this->files[$this->input_file_name]['name'],
                    $this->files[$this->input_file_name]['size'],
                    $this->files[$this->input_file_name]['type']
                );
                return false;
            } else {
                $Finfo = new \finfo();
                $file_mimetype = $Finfo->file($this->files[$this->input_file_name]['tmp_name'], FILEINFO_MIME_TYPE);
                if (is_array($this->file_extensions_mime_types[$file_extension]) && !in_array(strtolower($file_mimetype), array_map('strtolower', $this->file_extensions_mime_types[$file_extension]))) {
                    unset($file_extension, $Finfo);
                    $this->setErrorMessage(
                        sprintf(static::__('The uploaded file has invalid mime type. (%s : %s).'), $this->files[$this->input_file_name]['name'], $file_mimetype),
                        'RDU_INVALID_MIME',
                        $this->files[$this->input_file_name]['name'] . ' : ' . $file_mimetype,
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $file_mimetype
                    );
                    unset($file_mimetype);
                    return false;
                } elseif (!is_array($this->file_extensions_mime_types[$file_extension])) {
                    unset($file_extension, $file_mimetype, $Finfo);
                    $this->setErrorMessage(
                        static::__('Unable to validate mime type. The format of &quot;file_extensions_mime_types&quot; property is incorrect.'),
                        'RDU_UNABLE_VALIDATE_MIME',
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                }
                unset($file_mimetype, $Finfo);
            }
        }

        unset($file_extension);
        return true;
    }
552113
public function getMimeTypeFromFile($file)
	{
		$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
		if (array_key_exists($extension, $this->_alt_mime_types)) {
			return $this->_alt_mime_types[$extension];
		} else {
			return (new \Finfo(FILEINFO_MIME_TYPE))->file($file);
		}
	}
582965
public function getMimeType()
    {
        if (empty($this->mimeType)) {
            $resource = finfo_open(FILEINFO_MIME_TYPE);
            $this->mimeType = finfo_file($resource, $this->getRealPath());
        }

        return $this->mimeType;
    }
953794
public function getMimeType()
    {
        if (!$this->mimeType) {
            $finfo = finfo_open(FILEINFO_MIME_TYPE, $this->magicFile);
            if (!$finfo) {
                throw new \UnexpectedValueException('Failed to open fileinfo database');
            }
            $this->mimeType = finfo_file($finfo, $this->file);
        }
        return $this->mimeType;
    }
140902
public static function __getMimeType(&$file)
        {
            $type = false;
            // Fileinfo documentation says fileinfo_open() will use the
            // MAGIC env var for the magic file
            if (extension_loaded('fileinfo') && isset($_ENV['MAGIC']) && ($finfo = finfo_open(FILEINFO_MIME, $_ENV['MAGIC'])) !== false) {
                if (($type = finfo_file($finfo, $file)) !== false) {
                    // Remove the charset and grab the last content-type
                    $type = explode(' ', repl('; charset=', ';charset=', $type));
                    $type = array_pop($type);
                    $type = explode(';', $type);
                    $type = trim(array_shift($type));
                }
                finfo_close($finfo);

            // If anyone is still using mime_content_type()
            } elseif (function_exists('mime_content_type')) {
                $type = trim(mime_content_type($file));
            }

            if ($type !== false && strlen($type) > 0) {
                return $type;
            }

            // Otherwise do it the old fashioned way
            static $exts = array(
                'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png',
                'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'ico' => 'image/x-icon',
                'swf' => 'application/x-shockwave-flash', 'pdf' => 'application/pdf',
                'zip' => 'application/zip', 'gz' => 'application/x-gzip',
                'tar' => 'application/x-tar', 'bz' => 'application/x-bzip',
                'bz2' => 'application/x-bzip2', 'txt' => 'text/plain',
                'asc' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html',
                'css' => 'text/css', 'js' => 'text/javascript',
                'xml' => 'text/xml', 'xsl' => 'application/xsl+xml',
                'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav',
                'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg',
                'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php'
            );

            $ext = Inflector::lower(pathInfo($file, PATHINFO_EXTENSION));

            return isset($exts[$ext]) ? $exts[$ext] : 'application/octet-stream';
        }
1169153
public function guessMimeType($filepath)
    {
        $magic_file = $this->getFileManager()->getMagicFile();
        $mimetype = finfo_file(finfo_open(FILEINFO_MIME_TYPE, $magic_file), $filepath);

        $extension = pathinfo($filepath, PATHINFO_EXTENSION);
        $match_extension = $this->matchMimetypeExtension($mimetype, $extension);

        //Use default mimetype guesser if it is not found
        if ($mimetype == "application/octet-stream" || !$match_extension) {
            $mimetype = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $filepath);
        }

        $this->setMimetype($mimetype);

        if (isset(self::$humanReadableTypes[$mimetype])) {
            $this->setReadableType(self::$humanReadableTypes[$mimetype]);
        } else {
            $this->setReadableType("Undefined");
        }
        $this->setFileclass($mimetype);
    }
73402
public function getMimeTypes($extension)
    {
        if (!array_key_exists($extension, $this->extension_to_mime_types)) {
            return false;
        }

        return $this->extension_to_mime_types[$extension];
    }
1266607
protected function getMimeType($file)
    {
        $info = finfo_open(FILEINFO_MIME_TYPE);
        $mime = finfo_file($info, $file);
        finfo_close($info);

        return $mime;
    }
1347498
public function getMime()
    {
        if (!$this->mime)
        {
            $type = FileType::getFromFile($this->getFullPath());
            $this->mime = $type->getMimeType();
        }
        return $this->mime;
    }
943492
public static function _detectMimeType($file) {
		if (!function_exists('finfo_open')) {
			//throw new InternalErrorException('finfo_open() required - please enable');
		}

		// Treat non local files differently
		$pattern = '~^https?://~i';
		if (preg_match($pattern, $file)) {
			// @codingStandardsIgnoreStart
			$headers = @get_headers($file);
			// @codingStandardsIgnoreEnd
			if (!preg_match("|\b200\b|", $headers[0])) {
				return '';
			}
			foreach ($headers as $header) {
				if (strpos($header, 'Content-Type:') === 0) {
					return trim(substr($header, 13));
				}
			}
			return '';
		}

		if (!is_file($file)) {
			return '';
		}

		$finfo = finfo_open(FILEINFO_MIME);
		$mimetype = finfo_file($finfo, $file);
		if (($pos = strpos($mimetype, ';')) !== false) {
			$mimetype = substr($mimetype, 0, $pos);
		}
		if ($mimetype) {
			return $mimetype;
		}
		$extension = static::_getExtension($file);
		$mimeType = static::getMimeTypeByAlias($extension);
		if ($mimeType) {
			return $mimeType;
		}
		return 'application/octet-stream';
	}
1304800
public function getExpectedMimeTypes($file)
    {
        $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));

        // if the finfo php extension isn't loaded, we can't complete this check.
        if (!class_exists('finfo')) {
            throw new MimeUploadValidatorException('PHP extension finfo is not loaded');
        }

        // Attempt to figure out which mime types are expected/acceptable here.
        $expectedMimes = array();

        // Get the mime types set in framework core
        $knownMimes = Config::inst()->get(HTTP::class, 'MimeTypes');
        if (isset($knownMimes[$extension])) {
            $expectedMimes[] = $knownMimes[$extension];
        }

        // Get the mime types and their variations from mime validator
        $knownMimes = $this->config()->get('MimeTypes');
        if (isset($knownMimes[$extension])) {
            $mimes = (array) $knownMimes[$extension];

            foreach ($mimes as $mime) {
                if (!in_array($mime, $expectedMimes)) {
                    $expectedMimes[] = $mime;
                }
            }
        }

        return $expectedMimes;
    }
452088
static function defaultMimeType()
    {
        return array( 'name' => 'application/octet-stream',
                      'url' => false,
                      'filename' => false,
                      'dirpath' => false,
                      'basename' => false,
                      'suffix' => false,
                      'prefix' => false,
                      'suffixes' => false,
                      'prefixes' => false,
                      'is_valid' => true );
    }