Reputation: 597
I am new in laravel 4.
I want to upload photo with maximum dimensions 800x600.
Please help to guide me!
Upvotes: 1
Views: 7856
Reputation: 195
Check like below in your form validation.
'avatar' => 'dimensions:min_width=100,min_height=200'
Upvotes: 1
Reputation: 7746
Check validation like this
if ($validator->passes() && correct_size(Input::file('file'))) {
// do something
}
Create a validation function like this in which ever model you choose
public function correct_size($photo) {
$maxHeight = 100;
$maxWidth = 100;
list($width, $height) = getimagesize($photo);
return ( ($width <= $maxWidth) && ($height <= $maxHeight) );
}
you can decide if you want to use it statically or not. But my recommendation is not defining it statically if you would like to check other uploads using the same validation without the dependency.
Upvotes: 2
Reputation: 100175
you could simple use getImageSize(), as
list($width, $height) = getimagesize(Input::file('file'));
Upvotes: 12