{"record":{"id":"abb60e64cc99ab34","repo":"Intervention/image","slug":"unable-to-extract-file-extension-from-path-t","errorCode":null,"errorMessage":"Unable to extract file extension from path \"' . $this->path . '\"","messagePattern":"Unable to extract file extension from path \"' \\. \\$this->path \\. '\"","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Encoders/FilePathEncoder.php","lineNumber":40,"sourceCode":"        );\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see EncoderInterface::encode()\n     *\n     * @throws InvalidArgumentException\n     * @throws NotSupportedException\n     */\n    public function encode(ImageInterface $image): EncodedImageInterface\n    {\n        $extension = is_null($this->path) ?\n            $image->origin()->fileExtension() :\n            pathinfo($this->path, PATHINFO_EXTENSION);\n\n        if ($extension === null || $extension === '') {\n            throw new InvalidArgumentException(\n                'Unable to extract file extension from path \"' . $this->path . '\"',\n            );\n        }\n\n        return $image->encode(\n            $this->encoderByFileExtension(\n                $extension,\n            ),\n        );\n    }\n}\n","sourceCodeStart":22,"sourceCodeEnd":52,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Encoders/FilePathEncoder.php#L22-L52","documentation":"FilePathEncoder::encode() determines the target format from pathinfo($this->path, PATHINFO_EXTENSION), or from the origin file extension when the path is null. When the path carries no extension at all (pathinfo returns ''), or the origin fallback is null, it throws InvalidArgumentException because no format can be determined.","triggerScenarios":"Calling $image->save('photos/final') or $image->encodeUsingPath('/tmp/out') where the filename has no dot; saving dotfile-style names such as '.htaccess' (pathinfo reports no extension); or constructing new FilePathEncoder(null) for an image whose origin has no file extension.","commonSituations":"Filenames assembled from slugs, UUIDs or hashes where the extension part got lost during string building; security code that strips the original upload extension; template paths with a missing extension placeholder.","solutions":["Append a supported extension to the output path: 'photos/final.jpg'","Check the path before saving and default the extension when missing","If the extension is intentionally absent, encode by an explicit encoder first and write the result yourself"],"exampleFix":"// before\n$path = 'uploads/' . $post->slug; // 'uploads/my-blog-post' -> no extension\n$image->save($path);\n\n// after\n$path = 'uploads/' . $post->slug . '.webp';\n$image->save($path);","handlingStrategy":"validation","validationCode":"if (pathinfo($path, PATHINFO_EXTENSION) === '') {\n    $path .= '.jpg'; // ensure an extension is present\n}\n$image->save($path);","typeGuard":"function pathHasExtension(string $path): bool\n{\n    return pathinfo($path, PATHINFO_EXTENSION) !== '';\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $image->encodeUsingPath($path);\n} catch (InvalidArgumentException $e) {\n    $image->encodeUsingPath($path . '.png');\n}","preventionTips":["Assemble output paths as name + '.' + extension in one place","Test path-building code with slug-only and dotfile names","When in doubt, default the extension instead of trusting the input"],"tags":["php","intervention-image","encoder","file-path","save","invalid-argument"],"backgroundTag":"missing-file-extension","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}