Image Thumbnali

this my contrall

public function actionCreate()

{


	$model=new Cities;





	// Uncomment the following line if AJAX validation is needed


	// $this->performAjaxValidation($model);





	if(isset($_POST['Cities']))


	{


       $rnd = rand(0,9999);


            $model->attributes=$_POST['Cities'];


            $uploadedFile=CUploadedFile::getInstance($model,'image'); 


            // random number + file name


            $fileName = "{$rnd}-{$uploadedFile}"; 


            // get image with Number


            $model->image = $fileName;


	if($model->save())


			//image  uplode to rootDirectory


			$uploadedFile->saveAs(Yii::app()->basePath.'/../images/cities/'.$fileName);//save image


			$this->redirect(array('view','id'=>$model->city_id));


	}





	$this->render('create',array(


		'model'=>$model,


	));


}

how add thumbnail in this code plzzzzzzzzzzzzzzzzzzzzz

Hi

you can add this below line before save image


$folder = YiiBase::getPathOfAlias('webroot') . '/upload/event/';

        $thumb = Yii::app()->phpThumb->create($folder . $result['filename']);

        $thumb->resize(81, 81);

        $thumb->save($folder . 'thumb81/' . $result['filename']);

more refreance please see it…

www.yiiframework.com/extension/ephpthumb/

Hope it will be help.

Hi!

First of all you need to modify your code from this:




$fileName = "{$rnd}-{$uploadedFile}";



to this:




$fileName = "{$rnd}-{$uploadedFile->name}";



because the CUploadedFile::getInstance() method will return the instance the of uploaded file, not directly the name of the uploaded file.

Second: much better if you check out the $uploadedFile variable after calling the getInstance() method. For example:




$uploadedFile=CUploadedFile::getInstance($model,'image');

if($uploadedFile) {

	// You have an uploaded file and you can do the image saving and/or processing stuff.

}



But answering to your question, I can prefer you the easyimage extension.

Best regards!

PS: Sorry about my english!

thanks bro …thanks…

how i set default image if have not selected any image… Plzzz

check this wiki