{"id":"c26c28e09bcd88ea","repo":"laravel/framework","slug":"to-enable-support-for-guessing-extensions-please","errorCode":null,"errorMessage":"To enable support for guessing extensions, please install the symfony/mime package.","messagePattern":"To enable support for guessing extensions, please install the symfony/mime package\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Filesystem/Filesystem.php","lineNumber":444,"sourceCode":"     * @return string\n     */\n    public function extension($path)\n    {\n        return pathinfo($path, PATHINFO_EXTENSION);\n    }\n\n    /**\n     * Guess the file extension from the MIME type of a given file.\n     *\n     * @param  string  $path\n     * @return string|null\n     *\n     * @throws \\RuntimeException\n     */\n    public function guessExtension($path)\n    {\n        if (! class_exists(MimeTypes::class)) {\n            throw new RuntimeException(\n                'To enable support for guessing extensions, please install the symfony/mime package.'\n            );\n        }\n\n        return (new MimeTypes)->getExtensions($this->mimeType($path))[0] ?? null;\n    }\n\n    /**\n     * Get the file type of a given file.\n     *\n     * @param  string  $path\n     * @return string|false\n     */\n    public function type($path)\n    {\n        return filetype($path);\n    }\n","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Filesystem/Filesystem.php#L426-L462","documentation":"Thrown by Filesystem::guessExtension() when Symfony\\Component\\Mime\\MimeTypes is not loadable. guessExtension maps a file's MIME type back to one or more extensions using symfony/mime's reverse lookup table; without that package the mapping is unavailable and the method refuses to guess.","triggerScenarios":"Calling File::guessExtension($path) where symfony/mime is not installed (it is optional for illuminate/filesystem).","commonSituations":"Slim install of illuminate/filesystem without symfony/mime; building a minimal SaaS that pulls only selected Illuminate packages; CI image that prunes dev/suggest dependencies.","solutions":["Install the package: `composer require symfony/mime`.","If you only need the MIME type (not the extension), use File::mimeType() which uses PHP's finfo and needs no extra package.","Fall back to File::extension($path) for a purely path-based extension."],"exampleFix":"// before - throws without symfony/mime\n$ext = File::guessExtension($path);\n\n// after\n// shell: composer require symfony/mime\n// or alternative without the package:\n$ext = File::extension($path);","handlingStrategy":"validation","validationCode":"if (! class_exists(\\Symfony\\Component\\Mime\\MimeTypes::class)) {\n    return File::extension($path); // fallback\n}\nreturn File::guessExtension($path);","typeGuard":"function mimeGuessingAvailable(): bool\n{\n    return class_exists(\\Symfony\\Component\\Mime\\MimeTypes::class);\n}","tryCatchPattern":"try {\n    return File::guessExtension($path);\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'symfony/mime')) {\n        return File::extension($path);\n    }\n    throw $e;\n}","preventionTips":["Add symfony/mime to composer.json if you call guessExtension().","Fall back to File::extension() when the package is optional.","Document optional dependencies."],"tags":["filesystem","dependency","symfony","mime"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}