Check and skip file on upload in OnFileManagerBeforeUpload plugin event

Hi,

i would like to check the uploaded files via manager for image type and check the width of that image. In case the uploaded image is larger then a defined width of pixel i would like to prevent this file from upload.

I can check the width and return an error message for the user - but how can i prevent the Upload.

I have the following code inside a plugin triggered on the event “OnFileManagerBeforeUpload”:

list($width, $height, $type, $attr) = getimagesize($file['tmp_name']); 
    
if ($width >=10000 xor $height >= 10000) {
    $source->addError('', 'Error: Filesize is over 10.000 px.');
    return;
}

How can i skip the image from upload?

Thanks a lot…

It looks like the code checks if $file['error'] is not 0 or if $file['name'] is empty after “OnFileManagerBeforeUpload” is invoked and skips the file if it is the case.

Thanks a lot for this hint. Do you know how i can set $file[‘error’] to 1?
This does not work:

list($width, $height, $type, $attr) = getimagesize($file['tmp_name']); 
    
if ($width >=10000 xor $height >= 10000) {
    $source->addError('', 'Error: Filesize is over 10.000 px.');
    $file['error'] = 1;
    return;
}

Try something like this:

$f = &$scriptProperties['file'];
$f['error'] = 1;
1 Like

Thanks a lot! That works…