{"record":{"id":"dec3233a7d34e27f","repo":"octobercms/october","slug":"error-saving-remote-file-to-a-temporary-location-dec323","errorCode":null,"errorMessage":"Error saving remote file to a temporary location.","messagePattern":"Error saving remote file to a temporary location\\.","errorType":"exception","errorClass":"SystemException","httpStatus":null,"severity":"error","filePath":"modules/media/widgets/MediaManager.php","lineNumber":1831,"sourceCode":"        if (!File::isDirectory($fullSessionDirectoryPath)) {\n            File::makeDirectory($fullSessionDirectoryPath, 0755, true, true);\n            $sessionDirectoryCreated = true;\n        }\n\n        $tempFilePath = null;\n\n        try {\n            $extension = pathinfo($path, PATHINFO_EXTENSION);\n            $library = MediaLibrary::instance();\n            $originalThumbFileName = 'original.'.$extension;\n\n            // If the target dimensions are not provided, save the original image to the\n            // crop session directory and return its URL.\n            if (!$params) {\n                $tempFilePath = $fullSessionDirectoryPath.'/'.$originalThumbFileName;\n\n                if (!@File::put($tempFilePath, $library->get($path))) {\n                    throw new SystemException('Error saving remote file to a temporary location.');\n                }\n\n                $url = $this->getThumbnailImageUrl($sessionDirectoryPath.'/'.$originalThumbFileName);\n                $dimensions = getimagesize($tempFilePath);\n\n                return [\n                    'url' => $url,\n                    'dimensions' => $dimensions\n                ];\n            }\n\n            // If the target dimensions are provided, resize the original image and\n            // return its URL and dimensions.\n            $originalFilePath = $fullSessionDirectoryPath.'/'.$originalThumbFileName;\n            if (!File::isFile($originalFilePath)) {\n                throw new SystemException('The original image is not found in the cropping session directory.');\n            }\n","sourceCodeStart":1813,"sourceCodeEnd":1849,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/media/widgets/MediaManager.php#L1813-L1849","documentation":"SystemException thrown at MediaManager.php:1831 during the crop flow's first step (getImageUrl with no target params): the original media file fetched via MediaLibrary::get($path) could not be written with File::put() into the crop session directory under temp_path(). The original must be staged locally before a crop URL and its dimensions (getimagesize) can be returned to the popup.","triggerScenarios":"Opening the image crop popup for a file on a misbehaving media disk (S3/Cloudflare R2 credentials, network) or when the crop session directory under the temp path is not writable. Because the write is @-suppressed, any underlying PHP error surfaces only as this exception.","commonSituations":"Storage credentials rotated but config/filesystems.php not updated; temp storage mounted read-only in a container; permissions broken after deployment; media disk reachable for listing but failing on object GET.","solutions":["Test a direct read: MediaLibrary::instance()->get($path) in tinker for the cropped file; fix filesystems.disks.media if it fails.","Ensure the PHP user can create/write directories under temp_path() (chown/chmod storage; check open_basedir).","Watch for disk-full conditions on the temp volume with df -h."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight before opening the crop popup\n$library = \\System\\Classes\\MediaLibrary::instance();\nif (!$library->exists($path)) {\n    throw new RuntimeException('Media item not readable: ' . $path);\n}\nif (!is_writable(temp_path())) {\n    throw new RuntimeException('Temp directory not writable');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $result = $this->getImageUrl($path, $sessionKey, $params);\n} catch (\\System\\Classes\\SystemException $e) {\n    \\Log::error('Crop staging failed: ' . $e->getMessage());\n    Flash::error('Could not open the image for cropping. Check storage configuration.');\n}","preventionTips":["Verify media disk read access with a scheduled canary read.","Keep temp storage writable and non-ephemeral during editing sessions.","Alert on repeated staging failures — they usually mean rotated credentials."],"tags":["media-manager","crop","filesystem","s3","permissions","temp-files"],"backgroundTag":"file-write-failed","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}