how can i get height and width of an image on upload.Here is my sample code.
My Model class rules
public function rules()
{
return array(
array('image, image_name, height, width, type, category', 'required'),
array('image', 'file', 'types'=>'jpg, gif, png'),
array('height, width, type, hide, category', 'numerical', 'integerOnly'=>true),
array('image_name', 'length', 'max'=>30),
array('id, image, image_name, height, width, type, hide, category', 'safe', 'on'=>'search'),
);
}
My Controller action
public function actionCreate()
{
$model=new Images;
if(isset($_POST['Images']))
{
$model->attributes=$_POST['Images'];
if($file=CUploadedFile::getInstance($model,'image'))
{
$model->image_name=$file->name;
$model->type=$file->type;
$model->height=$file->height;
}
$model->image=$file;
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
'categories'=>$categories,
));
}
Here i am trying to load an image to database with this piece of code, but before saving image to database i need some image properties like (height, width, size , image name), for image searching purpose where as i am getting image name but not the remaining properties.