Image Thumbnali

this my contrall

public function actionCreate()


	$model=new Cities;

	// Uncomment the following line if AJAX validation is needed

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



       $rnd = rand(0,9999);



            // random number + file name

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

            // get image with Number

            $model->image = $fileName;


			//image  uplode to rootDirectory

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







how add thumbnail in this code plzzzzzzzzzzzzzzzzzzzzz


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…

Hope it will be help.


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:


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