{"record":{"id":"222851430757d27b","repo":"Intervention/image","slug":"path-is-longer-than-the-configured-max-value-of","errorCode":null,"errorMessage":"Path is longer than the configured max. value of \" . PHP_MAXPATHLEN","messagePattern":"Path is longer than the configured max\\. value of \" \\. PHP_MAXPATHLEN","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/File.php","lineNumber":79,"sourceCode":"\n    /**\n     * {@inheritdoc}\n     *\n     * @see FileInterface::save()\n     *\n     * @throws InvalidArgumentException\n     * @throws DirectoryNotFoundException\n     * @throws FileNotWritableException\n     * @throws StreamException\n     */\n    public function save(string $path): void\n    {\n        if ($path === '') {\n            throw new InvalidArgumentException('Path must not be an empty string');\n        }\n\n        if (strlen($path) > PHP_MAXPATHLEN) {\n            throw new InvalidArgumentException(\n                \"Path is longer than the configured max. value of \" . PHP_MAXPATHLEN,\n            );\n        }\n\n        $dir = pathinfo($path, PATHINFO_DIRNAME);\n\n        if (!is_dir($dir)) {\n            throw new DirectoryNotFoundException(\n                'Can\\'t write to path. Directory \"' . $dir . '\" does not exist',\n            );\n        }\n\n        if (!is_writable($dir)) {\n            throw new FileNotWritableException(\n                'Can\\'t write to path. Directory \"' . $dir . '\" is not writable',\n            );\n        }\n","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/File.php#L61-L97","documentation":"File::save() checks strlen($path) against PHP_MAXPATHLEN (a platform constant: 4096 on most Linux builds) and throws InvalidArgumentException when the target path exceeds it. This mirrors the OS limit, since file operations with longer paths would fail anyway.","triggerScenarios":"Building save paths that stack directories, slugs, UUIDs, timestamps and hashes until they exceed PHP_MAXPATHLEN; embedding very long identifiers (or accidentally a base64 blob) in the filename; deep directory nesting.","commonSituations":"Generated filenames derived from user titles or composite keys; content-addressed storage appending multiple hashes; accidentally concatenating file contents or URLs into the filename variable.","solutions":["Shorten the filename: keep a single hash or ID instead of stacked identifiers","Check strlen($path) <= PHP_MAXPATHLEN before calling save() and truncate or reject","Move long metadata into a database and use short keys as filenames"],"exampleFix":"// before\n$name = implode('-', [$post->slug, $uuid, $hash, time()]) . '.jpg'; // can exceed 4096\n$image->save($dir . '/' . $name);\n\n// after\n$name = hash('sha256', $post->slug . $uuid) . '.jpg'; // fixed 64 chars + ext\n$image->save($dir . '/' . $name);","handlingStrategy":"validation","validationCode":"if (strlen($path) > PHP_MAXPATHLEN) {\n    throw new InvalidArgumentException('Path exceeds PHP_MAXPATHLEN');\n}\n$encoded->save($path);","typeGuard":"function isPathWithinLimit(string $path): bool\n{\n    return strlen($path) <= PHP_MAXPATHLEN;\n}","tryCatchPattern":null,"preventionTips":["Prefer short hash-based filenames over stacked identifiers","Keep long metadata in a database, not in filenames","Bound generated filename length in your path-builder utility"],"tags":["php","intervention-image","file","save","path","filesystem-limits"],"backgroundTag":"path-too-long","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}