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:1398 when File::put() fails while copying the original file from the media library disk (MediaLibrary::get($path)) into a local temp file for thumbnail generation. The @ operator suppresses the PHP warning, so this exception is often the first visible symptom of an unreadable media disk or unwritable temp directory.

Source

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

                if (!is_numeric($width) || !is_numeric($height) || !is_numeric($lastModified)) {
                    throw new ApplicationException('Invalid input data');
                }

                if (!$thumbnailParams) {
                    $thumbnailParams = $this->getThumbnailParams();
                    $thumbnailParams['width'] = $width;
                    $thumbnailParams['height'] = $height;
                }

                $thumbnailPath = $this->getThumbnailImagePath($thumbnailParams, $path, $lastModified);
                $fullThumbnailPath = temp_path(ltrim($thumbnailPath, '/'));

                // Save the file locally
                $library = MediaLibrary::instance();
                $tempFilePath = $this->getLocalTempFilePath($path);

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

                // Resize the thumbnail and save to the thumbnails directory
                $this->resizeImage($fullThumbnailPath, $thumbnailParams, $tempFilePath);

                // Delete the temporary file
                File::delete($tempFilePath);
                $markup = $this->makePartial('thumbnail-image', [
                    'isError' => false,
                    'imageUrl' => $this->getThumbnailImageUrl($thumbnailPath)
                ]);
            }
        }
        catch (Exception $ex) {
            if ($tempFilePath) {
                File::delete($tempFilePath);
            }

View on GitHub (pinned to b608633a7e)

Solutions

  1. Verify the media disk reads work: check filesystems.disks.media credentials and run a test MediaLibrary::get() in tinker for the failing path.
  2. Check the web server user can write to the directory returned by temp_path() (e.g. storage/app/temp or sys_get_temp_dir) — fix with chown/chmod.
  3. Check df -h for a full temp disk and php.ini open_basedir for path exclusions.
Defensive patterns

Strategy: try-catch

Validate before calling

// Server-side smoke check before heavy use
$disk = Storage::disk(Config::get('cms.storage.media.disk', 'media'));
if (!$disk->has($path)) {
    throw new RuntimeException('Media item missing on disk: ' . $path);
}

Try / catch

try {
    $widget->onGenerateThumbnail();
} catch (\System\Classes\SystemException $e) {
    \Log::warning('Thumbnail generation failed: ' . $e->getMessage());
    // degrade gracefully: serve the original URL instead of a thumbnail
}

Prevention

When it happens

Trigger: onGenerateThumbnail for an image whose bytes cannot be fetched (S3/media disk credentials wrong, bucket unreachable, R2 adapter misconfigured) or cannot be written to the path returned by getLocalTempFilePath() (temp_path()/public not writable, disk full, open_basedir restriction).

Common situations: Wrong values in config/filesystems.php for the 'media' disk (missing key/secret/region); storage directory permissions after a server move or Docker volume mount; disk full on the temp partition; safe_mode/open_basedir blocking the temp path.

Related errors


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