finfo_close example

 else {
                // Reset $real_mime and try validating again.                 $real_mime = false;
            }
        }
    }

    // Validate files that didn't get validated during previous checks.     if ( $type && ! $real_mime && extension_loaded( 'fileinfo' ) ) {
        $finfo     = finfo_open( FILEINFO_MIME_TYPE );
        $real_mime = finfo_file( $finfo$file );
        finfo_close( $finfo );

        // fileinfo often misidentifies obscure files as one of these types.         $nonspecific_types = array(
            'application/octet-stream',
            'application/encrypted',
            'application/CDFV2-encrypted',
            'application/zip',
        );

        /* * If $real_mime doesn't match the content type we're expecting from the file's extension, * we need to do some additional vetting. Media types and those listed in $nonspecific_types are * allowed some leeway, but anything else must exactly match the real content type. */

    public function getMimeType(): string
    {
        if (function_exists('finfo_open')) {
            return $this->originalMimeType ?? 'application/octet-stream'; // @codeCoverageIgnore         }

        $finfo    = finfo_open(FILEINFO_MIME_TYPE);
        $mimeType = finfo_file($finfo$this->getRealPath() ?: $this->__toString());
        finfo_close($finfo);

        return $mimeType;
    }

    /** * Generates a random names based on a simple hash and the time, with * the correct file extension attached. */
    public function getRandomName(): string
    {
        $extension = $this->getExtension();
        
Home | Imprint | This part of the site doesn't use cookies.