octobercms/october · error · SystemException

Error saving remote file to a temporary location.

Error message

Error saving remote file to a temporary location.

What it means

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.

Source

Thrown at modules/media/widgets/MediaManager.php:1831

        if (!File::isDirectory($fullSessionDirectoryPath)) {
            File::makeDirectory($fullSessionDirectoryPath, 0755, true, true);
            $sessionDirectoryCreated = true;
        }

        $tempFilePath = null;

        try {
            $extension = pathinfo($path, PATHINFO_EXTENSION);
            $library = MediaLibrary::instance();
            $originalThumbFileName = 'original.'.$extension;

            // If the target dimensions are not provided, save the original image to the
            // crop session directory and return its URL.
            if (!$params) {
                $tempFilePath = $fullSessionDirectoryPath.'/'.$originalThumbFileName;

                if (!@File::put($tempFilePath, $library->get($path))) {
                    throw new SystemException('Error saving remote file to a temporary location.');
                }

                $url = $this->getThumbnailImageUrl($sessionDirectoryPath.'/'.$originalThumbFileName);
                $dimensions = getimagesize($tempFilePath);

                return [
                    'url' => $url,
                    'dimensions' => $dimensions
                ];
            }

            // If the target dimensions are provided, resize the original image and
            // return its URL and dimensions.
            $originalFilePath = $fullSessionDirectoryPath.'/'.$originalThumbFileName;
            if (!File::isFile($originalFilePath)) {
                throw new SystemException('The original image is not found in the cropping session directory.');
            }

View on GitHub (pinned to b608633a7e)

Solutions

  1. Test a direct read: MediaLibrary::instance()->get($path) in tinker for the cropped file; fix filesystems.disks.media if it fails.
  2. Ensure the PHP user can create/write directories under temp_path() (chown/chmod storage; check open_basedir).
  3. Watch for disk-full conditions on the temp volume with df -h.
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight before opening the crop popup
$library = \System\Classes\MediaLibrary::instance();
if (!$library->exists($path)) {
    throw new RuntimeException('Media item not readable: ' . $path);
}
if (!is_writable(temp_path())) {
    throw new RuntimeException('Temp directory not writable');
}

Try / catch

try {
    $result = $this->getImageUrl($path, $sessionKey, $params);
} catch (\System\Classes\SystemException $e) {
    \Log::error('Crop staging failed: ' . $e->getMessage());
    Flash::error('Could not open the image for cropping. Check storage configuration.');
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/dec3233a7d34e27f. Report an issue: GitHub.