{"record":{"id":"2ecbcdc7151e7f56","repo":"octobercms/october","slug":"error-creating-thumbnail-directory","errorCode":null,"errorMessage":"Error creating thumbnail directory","messagePattern":"Error creating thumbnail directory","errorType":"exception","errorClass":"SystemException","httpStatus":null,"severity":"error","filePath":"modules/media/widgets/MediaManager.php","lineNumber":1449,"sourceCode":"            ];\n        }\n    }\n\n    /**\n     * resizeImage\n     * @param string $fullThumbnailPath\n     * @param array $thumbnailParams\n     * @param string $tempFilePath\n     * @return void\n     */\n    protected function resizeImage($fullThumbnailPath, $thumbnailParams, $tempFilePath)\n    {\n        $thumbnailDir = dirname($fullThumbnailPath);\n        if (\n            !File::isDirectory($thumbnailDir)\n            && File::makeDirectory($thumbnailDir, 0755, true) === false\n        ) {\n            throw new SystemException('Error creating thumbnail directory');\n        }\n\n        $targetDimensions = $this->getTargetDimensions($thumbnailParams['width'], $thumbnailParams['height'], $tempFilePath);\n\n        $targetWidth = $targetDimensions[0];\n        $targetHeight = $targetDimensions[1];\n\n        Resizer::open($tempFilePath)\n            ->resize($targetWidth, $targetHeight, [\n                'mode' => $thumbnailParams['mode'],\n                'offset' => [0, 0]\n            ])\n            ->save($fullThumbnailPath)\n        ;\n\n        File::chmod($fullThumbnailPath);\n    }\n","sourceCodeStart":1431,"sourceCodeEnd":1467,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/media/widgets/MediaManager.php#L1431-L1467","documentation":"SystemException thrown in resizeImage() (MediaManager.php:1449) when the thumbnail's parent directory does not exist and File::makeDirectory(..., 0755, true) fails to create it. Thumbnails are cached under temp_path() in a nested path derived from the thumbnail parameters, so this is an environment-level failure, not bad user input.","triggerScenarios":"Generating a thumbnail whose target directory (temp path + hashed thumbnail path) cannot be created: directory owned by root after a deployment, read-only filesystem or container image, SELinux denying mkdir, or a full disk returning errors.","commonSituations":"Deployments where storage/ was copied with wrong ownership; Docker/Kubernetes containers with a read-only layer where temp_path() resolves inside the app; SELinux contexts on CentOS/RHEL; running under a different PHP-FPM user than the one that owns storage/.","solutions":["chown -R www-data:www-data storage (or chmod -R u+rwX) so the PHP user can create directories under the temp path.","Point temp to a writable volume: set cms.tempDir / use a mounted path for temp_path() in containerised setups.","Verify with sudo -u www-data mkdir <thumbnailDir> that creation succeeds; check SELinux audit logs if applicable."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Boot-time guard: ensure the thumbnails temp root is writable\n$dir = temp_path('public');\nif (!is_dir($dir)) {\n    @mkdir($dir, 0755, true);\n}\nif (!is_writable($dir)) {\n    throw new RuntimeException('Temp path not writable: ' . $dir);\n}","typeGuard":null,"tryCatchPattern":"try {\n    $this->resizeImage($fullPath, $params, $tempFile);\n} catch (\\System\\Classes\\SystemException $e) {\n    \\Log::error('Cannot create thumbnail dir: ' . $e->getMessage());\n    return $this->makePartial('thumbnail-image', ['isError' => true]);\n}","preventionTips":["chown storage/ to the PHP-FPM user in every deployment script.","Mount a writable volume at the temp path in containers.","Include a temp-path writability check in your health endpoint."],"tags":["media-manager","thumbnails","filesystem","permissions","docker","selinux"],"backgroundTag":"directory-creation-denied","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}