{"record":{"id":"84d8c2b524f019a9","repo":"Intervention/image","slug":"unable-to-determine-path-for-saving","errorCode":null,"errorMessage":"Unable to determine path for saving","messagePattern":"Unable to determine path for saving","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\EncoderException","httpStatus":null,"severity":"error","filePath":"src/Image.php","lineNumber":313,"sourceCode":"     * {@inheritdoc}\n     *\n     * @see ImageInterface::save()\n     *\n     * @throws InvalidArgumentException\n     * @throws EncoderException\n     * @throws DirectoryNotFoundException\n     * @throws FileNotWritableException\n     * @throws StreamException\n     * @throws NotSupportedException\n     */\n    public function save(?string $path = null, mixed ...$options): ImageInterface\n    {\n        if ($path === '') {\n            throw new InvalidArgumentException('Argument $path must not be an empty string');\n        }\n\n        if (is_null($path) && is_null($this->origin()->filePath())) {\n            throw new EncoderException('Unable to determine path for saving');\n        }\n\n        $path = is_null($path) ? $this->origin()->filePath() : $path;\n\n        try {\n            // try to determine encoding format by file extension of the path\n            $encoded = $this->encode(new FilePathEncoder($path, ...$options));\n        } catch (EncoderException) {\n            // fallback to encoding format by media type\n            $encoded = $this->encode(new MediaTypeEncoder(null, ...$options));\n        }\n\n        $encoded->save($path);\n\n        return $this;\n    }\n\n    /**","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Image.php#L295-L331","documentation":"save() with no path argument tries to reuse the file path stored in the image's origin. Images that never came from a file — created with ImageManager::create(), decoded from a binary string, base64 data, a stream, or a data URI — have no origin path, so there is nothing to determine and an EncoderException is thrown. The library refuses to guess a write location.","triggerScenarios":"$manager->create(100, 100)->save();, $manager->read($binaryString)->save();, or any image whose origin()->filePath() is null, with save() called without arguments. save('/path.jpg') with a real path never triggers this.","commonSituations":"Generating thumbnails/derivatives from uploaded file contents (Laravel UploadedFile ->getContent() gives a string, not a path), creating canvases or watermarks programmatically, or refactoring code that previously always loaded from a file path.","solutions":["Pass an explicit output path: $image->save('/storage/thumbs/foo.jpg')","If you have the source file, read from the path (not from its contents) so the origin is recorded: $manager->read($uploadedFile->getPathname())","Chain ->encode('png') and handle the EncodedImage result yourself when no filesystem path is wanted"],"exampleFix":"// before\n$image = $manager->read($request->file('avatar')->getContent());\n$image->save(); // EncoderException: no origin path\n\n// after\n$image = $manager->read($request->file('avatar')->getPathname());\n$image->save(); // rewrites the uploaded file, or pass an explicit path","handlingStrategy":"validation","validationCode":"$path = $image->origin()->filePath();\nif ($path === null) {\n    $path = $outputDirectory . '/' . $filename . '.jpg';\n}\n$image->save($path);","typeGuard":"function hasOriginPath(ImageInterface $image): bool\n{\n    return $image->origin()->filePath() !== null;\n}","tryCatchPattern":"try {\n    $image->save();\n} catch (EncoderException $e) {\n    $image->save('/tmp/fallback-' . uniqid() . '.jpg');\n}","preventionTips":["Always pass an explicit path when the image was created from scratch or decoded from bytes","Read uploads via getPathname() (not getContent()) when you want origin-based save()","Reserve no-argument save() for images known to have a file origin"],"tags":["save","encoder","origin","path"],"backgroundTag":"missing-file-path","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}