Reputation: 23
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?
Upvotes: 2
Views: 660
Reputation: 973
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.
Upvotes: 4
Reputation: 305
Use this it will give width and height of the image.
list($width, $height) = getimagesize($filename);
Upvotes: 0