Yii Framework Forum: Image Validation - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Image Validation Validating image width and height to be some max value. Rate Topic: -----

#1 User is offline   Satish Dongol 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 19-January 14

Posted 19 January 2014 - 11:51 PM

How to validate an image in Yii framework so that the user should upload image of certain resolution or below? ex: resolution below 600x500 not bigger than that??

Please help! Thanks!
0

#2 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,327
  • Joined: 21-February 11
  • Location:Greece

Posted 20 January 2014 - 05:47 AM

Hi

you should make your own validator

public function imageSize($attribute,$params)
{
//...$uplodedImageUrl is the path of uploaded file
$info = getimagesize($uplodedImageUrl);
$imagewidth = $info[0];
$imageheight = $info[1];

if ($imagewidth>600 || $imageheight>500)
$this->addError('image','The image should be maximum 600x500');

}


add in rules method
...
array('image','imageSize')
...

Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users