Ad

Validating Fileupload(image Dimensions) In Backend Octobercms

im creating a plugin where im using fileupload field type in Backend. I have an realation $attachOne and i need to validade image dimensions(height and width), is ther a way to do it?

Ad

Answer

You would need to add validation logic to the model. Where the relation is called somerelation, define a method like this in the model class:

public function beforeValidate()
{
    $file = $this->somerelation()->withDeferred($this->sessionKey)->first();
    $filename = $file->getLocalPath();
    list($width, $height) = getimagesize($filename);

    if ($width < 800) {
        throw new ValidationException(['somerelation' => 'Width must be greater than 800']);
    }
}

For this method override to work, make sure the model already uses the October\Rain\Database\Traits\Validation trait. For it only to occur in the backend, a quick check of App::runningInBackend() should do the trick.

Ad
source: stackoverflow.com
Ad