Skip to content

Instantly share code, notes, and snippets.

@sohelrana820
Created May 12, 2014 13:25
Show Gist options
  • Save sohelrana820/0f6ed4123265f19fd054 to your computer and use it in GitHub Desktop.
Save sohelrana820/0f6ed4123265f19fd054 to your computer and use it in GitHub Desktop.
public function imgValidate()
{
$validateImg = array(
'image' => array(
'isImage' => array(
'rule' => array('isImage'),
'message' => 'Please provide an image!',
),
'dimension' => array(
'rule' => array('dimension', 320, 100),
'message' => 'Your image dimensions are incorrect: 320X100'
),
'size' => array(
'rule' => array('size', 10240, 204800),
'message' => 'Image size should be between 10kb - 200kb'
),
'rule3' => array(
'rule' => array(
'extension',
array('gif', 'jpeg', 'png', 'jpg')
),
'message' => "Please supply a valid image (allow gif, jpeg, png and jpg format)"
),
'rule4' => array(
'rule' => array('fileSize', '<=', '1MB'),
'message' => 'Image must be less than 1MB'
),
),
);
$this->validate = $validateImg;
return $this->validates();
}
public function dimension($data, $width = null, $height = null) {
$dimension = $file = getimagesize($data['image']['tmp_name']);
if($dimension['0'] == $width && $dimension['1'] == $height)
{
return true;
}
return false;
}
public function isImage($data) {
if(!empty($data['image']['name']))
{
return true;
}
return false;
}
public function size($data, $min, $max) {
$size =$data['image']['size'] ;
if($size > $min && $size < $max)
{
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment