I am new in laravel 4.
I want to upload photo with maximum dimensions 800x600.
Please help to guide me!
您可以简单地使用getImageSize()作为
list($width, $height) = getimagesize(Input::file('file'));
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.
在表单验证中进行如下检查。
'avatar' => 'dimensions:min_width=100,min_height=200'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.