{"record":{"id":"fffe730071ec6b5f","repo":"Intervention/image","slug":"failed-to-write-file-to-path-path","errorCode":null,"errorMessage":"Failed to write file to path \" . $path","messagePattern":"Failed to write file to path \" \\. \\$path","errorType":"exception","errorClass":"FileNotWritableException","httpStatus":null,"severity":"error","filePath":"src/File.php","lineNumber":108,"sourceCode":"        }\n\n        if (!is_writable($dir)) {\n            throw new FileNotWritableException(\n                'Can\\'t write to path. Directory \"' . $dir . '\" is not writable',\n            );\n        }\n\n        if (is_file($path) && !is_writable($path)) {\n            throw new FileNotWritableException(\n                \"Can't write to path. Existing file \" . $path . \" is not writable\",\n            );\n        }\n\n        // write data\n        $saved = file_put_contents($path, $this->toStream());\n\n        if ($saved === false) {\n            throw new FileNotWritableException(\n                \"Failed to write file to path \" . $path,\n            );\n        }\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see FileInterface::toString()\n     *\n     * @throws StreamException\n     */\n    public function toString(): string\n    {\n        $data = stream_get_contents($this->toStream(), offset: 0);\n\n        if ($data === false) {\n            throw new StreamException('Unable to read data from stream');","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/File.php#L90-L126","documentation":"File::save() finally writes with file_put_contents($path, $this->toStream()) and throws FileNotWritableException when that call returns false. All pre-checks (directory exists, directory writable, existing file writable) passed, so the failure happened during the write itself: the disk or inode pool is full, a quota was hit, or the filesystem errored (NFS/remote mount issues, fs corruption).","triggerScenarios":"Writing a large encoded image to a full disk (df shows 100%); hitting an inode limit; exceeding a user/group quota on shared hosting; writing to a failing NFS mount where metadata checks still succeed.","commonSituations":"Upload/storage volumes filling up in production; log or image caches growing unbounded; shared hosting quotas; long-running jobs whose disk filled after the pre-checks passed.","solutions":["Check free space and inodes: df -h and df -i; free space or expand the volume","Catch FileNotWritableException around save(), surface an actionable error (storage full) instead of a generic failure, and alert ops","Add disk-space monitoring and a best-effort guard with disk_free_space() before heavy write batches"],"exampleFix":"// before\n$image->save($path); // throws 'Failed to write file to path ...' when disk is full\n\n// after\ntry {\n    $image->save($path);\n} catch (FileNotWritableException $e) {\n    Logger::error('image save failed', ['path' => $path, 'free' => disk_free_space(dirname($path))]);\n    throw new RuntimeException('Image could not be stored; disk full or quota exceeded', 0, $e);\n}","handlingStrategy":"try-catch","validationCode":"$dir = pathinfo($path, PATHINFO_DIRNAME);\nif (disk_free_space($dir) === false || disk_free_space($dir) < $expectedBytes) {\n    throw new RuntimeException('Insufficient disk space for image write');\n}\n// best-effort only: the disk can still fill between check and write","typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\FileNotWritableException;\n\ntry {\n    $image->save($path);\n} catch (FileNotWritableException $e) {\n    // pre-checks passed, so the write itself failed: disk full, quota, fs error\n    report('Image write failed: ' . $path . ' free=' . disk_free_space(dirname($path)));\n    throw $e;\n}","preventionTips":["Monitor free space and inodes (df -h, df -i) on upload volumes","Alert on FileNotWritableException separately from permission errors","Prune generated thumbnails/caches so disks cannot grow unbounded"],"tags":["php","intervention-image","file","save","disk-full","filesystem"],"backgroundTag":"disk-write-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}