问题描述
我是laravel .im中的新手,试图验证图像的尺寸.我要使用controller.php中的验证代码来最小尺寸(宽度= 100,高度= 50).iam 'galimg'=>'required | max:200kb | DimensionMin(300,300)| Mimes:jpeg,jpg,gif,png ,pneg'
但是DimensionMin(300,300)不起作用....我认为自定义验证规则是可能的..但是我不知道如何使用它?在哪里使用?这是我的controller.php代码
Iam new in laravel .im trying to validate dimensions of image .i want dimensions minimum(width=100,height=50).iam using validation code in controller.php is here 'galimg'=>'required|max:200kb|DimensionMin(300,300)|Mimes:jpeg,jpg,gif,png ,pneg'
but DimensionMin(300,300) is not work....i think custom validation rule is possible ..but i dont know how to use it ?and where ? this is my controller.php code
public function getgallery()
{
$validate=Validator::make(Input::all(),array(
'galname'=>'required|max:20',
'galimg'=>'required|max:400kb|Dimensionmin(300,300)|Mimes:jpeg,jpg,gif,png
,pneg'));
if($validate->fails())
{ return Redirect::route('getgallery')
->withErrors($validate)->withInput(); }
else
{ $max_image = 3;
if(ForumGallery::all()->count() < $max_image)
{ $file=Input::file('galimg');
$filename=$file->getClientOriginalName();
$file->move('uploads',$filename);
ForumGallery::create(['galname'=>Input::get('galname'),
'galimg'=>$filename]);
return Redirect::route('addgallery');
}
else
{return Redirect::route('gallery')
->with('success','Max Image Upload Reached!');
} }}
推荐答案
您可以使用这个很棒的库来检测图像尺寸此处
You can use this awesome library for detecting your image dimension here
安装完成后,您可以像这样在控制器中使用它:
afte done installing you can use it in your controller like this one :
$validate=Validator::make(Input::all(),array(
'galname'=>'required|max:20',
'galimg'=>'required|mimes:jpeg,jpg,gif,png,pneg|image_size:1200,800'));
规则应为1200宽,800高或宽度= 1200且高度= 800
the rules should be 1200 wide and 800 tall or width = 1200 and height = 800
注意:尺寸以像素为单位希望对您有帮助.
这篇关于在laravel中插入数据库之前如何验证图像尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!