octobercms/october · error · SystemException
Invalid selection data.
Error message
Invalid selection data.
What it means
SystemException thrown in cropImage() (MediaManager.php:1923) when the posted selection data array lacks one of the four required keys: x, y, w, h. Each selection parameter is checked with array_key_exists before it can be cast to int, so null values also count as missing (array_key_exists passes for null, but the subsequent is_numeric check on null throws the sibling error).
Source
Thrown at modules/media/widgets/MediaManager.php:1923
{
$originalFileName = basename($path);
$path = rtrim(dirname($path), '/').'/';
$fileName = basename($imageSrcPath);
if (
strpos($fileName, '..') !== false ||
strpos($fileName, '/') !== false ||
strpos($fileName, '\\') !== false
) {
throw new SystemException('Invalid image file name.');
}
$selectionParams = ['x', 'y', 'w', 'h'];
foreach ($selectionParams as $paramName) {
if (!array_key_exists($paramName, $selectionData)) {
throw new SystemException('Invalid selection data.');
}
if (!is_numeric($selectionData[$paramName])) {
throw new SystemException('Invalid selection data.');
}
$selectionData[$paramName] = (int) $selectionData[$paramName];
}
$sessionDirectoryPath = $this->getCropSessionDirPath($cropSessionKey);
$fullSessionDirectoryPath = temp_path($sessionDirectoryPath);
if (!File::isDirectory($fullSessionDirectoryPath)) {
throw new SystemException('The image editing session is not found.');
}
// Find the image on the disk and resize it
$imagePath = $fullSessionDirectoryPath.'/'.$fileName;View on GitHub (pinned to b608633a7e)
Solutions
- Post selection as an array/object with exactly the keys x, y, w, h, all present.
- Double-check the key names in the request payload (w/h, not width/height) when building custom crop UIs.
- Send selection as proper form-encoded or parsed JSON data so PHP receives an array, not a scalar string.
Example fix
// before
data: { selection: { x: 10, y: 10, w: 200, height: 150 } }
// after
data: { selection: { x: 10, y: 10, w: 200, h: 150 } } Defensive patterns
Strategy: validation
Validate before calling
const s = selection || {};
if (!['x', 'y', 'w', 'h'].every(k => k in s)) {
alert('Selection is incomplete.');
return;
}
$.request('crop', { data: { selection: s, ... } }); Type guard
function hasSelectionKeys(s) {
return !!s && typeof s === 'object'
&& ['x', 'y', 'w', 'h'].every(k => Object.prototype.hasOwnProperty.call(s, k));
} Prevention
- Send selection as a parsed object (FormData field or JSON), not a stringified blob.
- Freeze the key contract (x, y, w, h) in integration tests against the crop handler.
When it happens
Trigger: Calling the crop apply handler with selection missing a key — e.g. {x: 10, y: 10, w: 200} with no h, selection sent as a JSON string instead of a parsed array, or keys named width/height instead of w/h.
Common situations: Custom crop front-ends mapping UI fields to the wrong key names; serialising the selection object to a string so the server sees no array keys at all; integration code written against a different cropping API.
Related errors
- Invalid image file name.
- Error saving remote file to a temporary location.
- The original image is not found in the cropping session dire
- The image editing session is not found.
- The image is not found on the disk.
AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21).
Data as JSON: /api/errors/94e9e0e6df82f985.
Report an issue: GitHub.