Image Upload with content

I am trying to upload image with json.When i click on the save button , nothing save to the database.I am trying to find out the problem for long time.Please help me.

My form file is:

<?php

$form = $this->beginWidget(‘CActiveForm’, array(

'id' =&gt; 'employees-form',


'action' =&gt; &#036;this-&gt;createUrl('employees/create'),


'enableAjaxValidation' =&gt; false,


'htmlOptions'=&gt;array('enctype'=&gt;'multipart/form-data'),


'enableClientValidation' =&gt; true,


'clientOptions' =&gt; array('validateOnSubmit' =&gt; true),


    ));

?>

<div class="formDiv">

&lt;fieldset&gt;


    &lt;legend&gt;&lt;?php echo (&#036;model-&gt;isNewRecord ? 'Add New Employee Info' : 'Update Employee Info'); ?&gt;&lt;/legend&gt;


    &lt;table&gt;


                   


        &lt;tr&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;labelEx(&#036;model, 'id_no'); ?&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;textField(&#036;model, 'id_no', array('maxlength' =&gt; 20)); ?&gt;&lt;span class=&quot;heighlightSpan&quot;&gt;Keep blank to auto generate&lt;/span&gt;&lt;/td&gt;


        &lt;/tr&gt;


        &lt;tr&gt;


            &lt;td&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;error(&#036;model, 'id_no'); ?&gt;&lt;/td&gt;


        &lt;/tr&gt;


        &lt;tr&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;labelEx(&#036;model, 'full_name'); ?&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;textField(&#036;model, 'full_name', array('maxlength' =&gt; 255)); ?&gt;&lt;/td&gt;            


        &lt;/tr&gt;


        &lt;tr&gt;


            &lt;td&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;error(&#036;model, 'full_name'); ?&gt;&lt;/td&gt;


        &lt;/tr&gt;


        &lt;tr&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;labelEx(&#036;model, 'designation_id'); ?&gt;&lt;/td&gt;


            &lt;td&gt;


                &lt;?php


                echo &#036;form-&gt;dropDownList(


                        &#036;model, 'designation_id', CHtml::listData(Designations::model()-&gt;allInfos(), 'id', 'designation'), array(


                    'prompt' =&gt; 'Select',


                ));


                ?&gt;


                &lt;?php


                echo CHtml::link('', &quot;&quot;, // the link for open the dialog


                        array(


                    'class' =&gt; 'add-additional-btn',


                    'onclick' =&gt; &quot;{addSections(); &#036;('#dialogSections').dialog('open');}&quot;));


                ?&gt;





                &lt;?php


                &#036;this-&gt;beginWidget('zii.widgets.jui.CJuiDialog', array(// the dialog


                    'id' =&gt; 'dialogSections',


                    'options' =&gt; array(


                        'title' =&gt; 'Add Designation',


                        'autoOpen' =&gt; false,


                        'modal' =&gt; true,


                        'width' =&gt; 550,


                        'resizable' =&gt; false,


                    ),


                ));


                ?&gt;


                &lt;div class=&quot;divForForm&quot;&gt;


                    &lt;div class=&quot;ajaxLoaderFormLoad&quot; style=&quot;display: none;&quot;&gt;&lt;img src=&quot;&lt;?php echo Yii::app()-&gt;theme-&gt;baseUrl; ?&gt;/images/ajax-loader.gif&quot; /&gt;&lt;/div&gt;


                &lt;/div&gt;





                &lt;?php &#036;this-&gt;endWidget(); ?&gt;





                &#60;script type=&quot;text/javascript&quot;&gt;


                    // here is the magic


                    function addSections() {

<?php

echo CHtml::ajax(array(

'url' =&gt; array('designations/create'),


'data' =&gt; &quot;js:&#036;(this).serialize()&quot;,


'type' =&gt; 'post',


'dataType' =&gt; 'json',


'beforeSend' =&gt; &quot;function(){


    &#036;('.ajaxLoaderFormLoad').show();


}&quot;,


'complete' =&gt; &quot;function(){


    &#036;('.ajaxLoaderFormLoad').hide();


}&quot;,


'success' =&gt; &quot;function(data){


                                    if (data.status == 'failure')


                                    {


                                        &#036;('#dialogSections div.divForForm').html(data.div);


                                              // Here is the trick: on submit-&gt; once again this function&#33;


                                        &#036;('#dialogSections div.divForForm form').submit(addSections);


                                    }


                                    else


                                    {


                                        &#036;('#dialogSections div.divForForm').html(data.div);


                                        setTimeout(&#092;&quot;&#036;('#dialogSections').dialog('close') &#092;&quot;,1000);


                                        &#036;('#Employees_designation_id').append('&lt;option selected value='+data.value+'&gt;'+data.label+'&lt;/option&gt;');


                                    }


                                                            }&quot;,

))

?>;

                        return false;


                    }


                &lt;/script&gt; 


            &lt;/td&gt;


        &lt;/tr&gt;


        &lt;tr&gt;


            &lt;td&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;error(&#036;model, 'designation_id'); ?&gt;&lt;/td&gt;


        &lt;/tr&gt;


        &lt;tr&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;labelEx(&#036;model, 'department_id'); ?&gt;&lt;/td&gt;


            &lt;td&gt;


                &lt;?php


                echo &#036;form-&gt;dropDownList(


                        &#036;model, 'department_id', CHtml::listData(Departments::model()-&gt;findAll(), 'id', 'department_name'), array(


                    'prompt' =&gt; 'Select',


                ));


                ?&gt;


                &lt;?php


                echo CHtml::link('', &quot;&quot;, // the link for open the dialog


                        array(


                    'class' =&gt; 'add-additional-btn',


                    'onclick' =&gt; &quot;{addDepartment(); &#036;('#dialogAddDepartment').dialog('open');}&quot;));


                ?&gt;





                &lt;?php


                &#036;this-&gt;beginWidget('zii.widgets.jui.CJuiDialog', array(// the dialog


                    'id' =&gt; 'dialogAddDepartment',


                    'options' =&gt; array(


                        'title' =&gt; 'Add Department',


                        'autoOpen' =&gt; false,


                        'modal' =&gt; true,


                        'width' =&gt; 550,


                        'resizable' =&gt; false,


                    ),


                ));


                ?&gt;


                &lt;div class=&quot;divForForm&quot;&gt;


                    &lt;div class=&quot;ajaxLoaderFormLoad&quot; style=&quot;display: none;&quot;&gt;&lt;img src=&quot;&lt;?php echo Yii::app()-&gt;theme-&gt;baseUrl; ?&gt;/images/ajax-loader.gif&quot; /&gt;&lt;/div&gt;


                &lt;/div&gt;





                &lt;?php &#036;this-&gt;endWidget(); ?&gt;





                &#60;script type=&quot;text/javascript&quot;&gt;


                    // here is the magic


                    function addDepartment() {

<?php

echo CHtml::ajax(array(

'url' =&gt; array('departments/createDepartmentFromOutSide'),


'data' =&gt; &quot;js:&#036;(this).serialize()&quot;,


'type' =&gt; 'post',


'dataType' =&gt; 'json',


'beforeSend' =&gt; &quot;function(){


    &#036;('.ajaxLoaderFormLoad').show();


}&quot;,


'complete' =&gt; &quot;function(){


    &#036;('.ajaxLoaderFormLoad').hide();


}&quot;,


'success' =&gt; &quot;function(data){


                                    if (data.status == 'failure')


                                    {


                                        &#036;('#dialogAddDepartment div.divForForm').html(data.div);


                                              // Here is the trick: on submit-&gt; once again this function&#33;


                                        &#036;('#dialogAddDepartment div.divForForm form').submit(addDepartment);


                                    }


                                    else


                                    {


                                        &#036;('#dialogAddDepartment div.divForForm').html(data.div);


                                        setTimeout(&#092;&quot;&#036;('#dialogAddDepartment').dialog('close') &#092;&quot;,1000);


                                        &#036;('#Employees_department_id').append('&lt;option selected value='+data.value+'&gt;'+data.label+'&lt;/option&gt;');


                                    }


                                                            }&quot;,

))

?>;

                        return false;


                    }


                &lt;/script&gt; 


            &lt;/td&gt;


        &lt;/tr&gt;


        &lt;tr&gt;


            &lt;td&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;error(&#036;model, 'department_id'); ?&gt;&lt;/td&gt;


        &lt;/tr&gt;


        &lt;tr&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;labelEx(&#036;model, 'contact_no'); ?&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;textField(&#036;model, 'contact_no', array('maxlength' =&gt; 20)); ?&gt;&lt;/td&gt;


        &lt;/tr&gt;


  [color=&quot;#9ACD32&quot;]   &lt;tr&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;labelEx(&#036;model, 'signature'); ?&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;fileField(&#036;model, 'signature') ?&gt;&lt;/td&gt;


        &lt;/tr&gt;[/color]


        &lt;tr&gt;


            &lt;td&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;error(&#036;model, 'signature'); ?&gt;&lt;/td&gt;


        &lt;/tr&gt;





        &lt;tr&gt;


            &lt;td&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;error(&#036;model, 'contact_no'); ?&gt;&lt;/td&gt;


        &lt;/tr&gt;


        &lt;tr&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;labelEx(&#036;model, 'email'); ?&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;textField(&#036;model, 'email', array('maxlength' =&gt; 50)); ?&gt;&lt;/td&gt;


        &lt;/tr&gt;


        &lt;tr&gt;


            &lt;td&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;error(&#036;model, 'email'); ?&gt;&lt;/td&gt;


        &lt;/tr&gt;


        &lt;tr&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;labelEx(&#036;model, 'address'); ?&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;textArea(&#036;model, 'address', array('rows' =&gt; 4, 'cols' =&gt; 20)); ?&gt;&lt;/td&gt;


        &lt;/tr&gt;


        &lt;tr&gt;


            &lt;td&gt;&lt;/td&gt;


            &lt;td&gt;&lt;?php echo &#036;form-&gt;error(&#036;model, 'address'); ?&gt;&lt;/td&gt;


        &lt;/tr&gt;


    &lt;/table&gt;


&lt;/fieldset&gt;





&lt;fieldset class=&quot;tblFooters&quot;&gt;


    &lt;span id=&quot;ajaxLoader&quot; style=&quot;display: none;&quot;&gt;&lt;img src=&quot;&lt;?php echo Yii::app()-&gt;theme-&gt;baseUrl; ?&gt;/images/ajax-loader.gif&quot; /&gt;&lt;/span&gt;


    &lt;?php


    echo CHtml::ajaxSubmitButton('Save', CHtml::normalizeUrl(array('employees/create', 'render' =&gt; true)), array(


        'dataType' =&gt; 'json',


        'type' =&gt; 'post',


        'success' =&gt; 'function(data) {


            &#036;(&quot;#ajaxLoader&quot;).hide();  


                if(data.status==&quot;success&quot;){


                    &#036;(&quot;#formResultError&quot;).hide();


                    &#036;(&quot;#formResult&quot;).fadeIn();


                    &#036;(&quot;#formResult&quot;).html(&quot;Data saved successfully.&quot;);


                    &#036;(&quot;#employees-form&quot;)[0].reset();


                    &#036;(&quot;#formResult&quot;).animate({opacity:1.0},1000).fadeOut(&quot;slow&quot;);


                    &#036;.fn.yiiGridView.update(&quot;employees-grid&quot;, {


	data: &#036;(this).serialize()


});


                }else{


                    &#036;(&quot;#formResult&quot;).hide();


                    &#036;(&quot;#formResultError&quot;).show();


                    &#036;(&quot;#formResultError&quot;).html(&quot;Data not saved. Pleae solve the above errors.&quot;);


                    &#036;.each(data, function(key, val) {


                        &#036;(&quot;#employees-form #&quot;+key+&quot;_em_&quot;).html(&quot;&quot;+val+&quot;&quot;);                                                    


                        &#036;(&quot;#employees-form #&quot;+key+&quot;_em_&quot;).show();


                    });


                }       


            }',


        'beforeSend' =&gt; 'function(){                        


            &#036;(&quot;#ajaxLoader&quot;).show();


         }'


    ));


    ?&gt;


&lt;/fieldset&gt;


&lt;div id=&quot;formResult&quot; class=&quot;ajaxTargetDiv&quot; style=&quot;display: none;&quot;&gt;&lt;/div&gt;


&lt;div id=&quot;formResultError&quot; class=&quot;ajaxTargetDivErr&quot; style=&quot;display: none;&quot;&gt;&lt;/div&gt;

</div>

<?php $this->endWidget(); ?>

My controller actionCreate() is:

public function actionCreate() {

    &#036;model = new Employees;





    // Uncomment the following line if AJAX validation is needed


    &#036;this-&gt;performAjaxValidation(&#036;model);





    if (isset(&#036;_POST['Employees'])) {


        &#036;model-&gt;attributes = &#036;_POST['Employees'];


        &#036;image = CUploadedFile::getInstance(&#036;model, 'signature');


        &#036;ext = pathinfo(&#036;image, PATHINFO_EXTENSION);


        &#036;rnd = rand(0, 9999);


        &#036;fileName = &quot;{&#036;rnd}-&quot; . &#036;ext;





        &#036;valid = &#036;model-&gt;validate();


        &#036;model-&gt;signature = &#036;fileName;








        if (&#036;model-&gt;save()) {


            &#036;image-&gt;saveAs(Yii::app()-&gt;theme-&gt;baseUrl . '/images/' . &#036;fileName);


            //do anything here


            echo CJSON::encode(array(


                'status' =&gt; 'success',


            ));


            Yii::app()-&gt;end();


        } else {


            &#036;error = CActiveForm::validate(&#036;model);


            if (&#036;error &#33;= '[]')


                echo &#036;error;


            Yii::app()-&gt;end();


        }


    }else {


        &#036;this-&gt;render('admin', array(


            'model' =&gt; &#036;model,


        ));


    }


}

My model rule is:

public function rules() {


    // NOTE: you should only define rules for those attributes that


    // will receive user inputs.


    return array(


        array('id_no, full_name, designation_id, department_id, contact_no', 'required'),


        array('id_no', 'unique', 'caseSensitive' =&gt; FALSE),


        array('designation_id, department_id', 'numerical', 'integerOnly' =&gt; true),


        array('full_name, id_no', 'length', 'max' =&gt; 255),


        array('contact_no', 'length', 'max' =&gt; 20),


        array('email', 'email'),

[color="#9ACD32"] array(‘signature’, ‘file’,‘types’=>‘jpg, gif, png’,‘safe’ => false,‘allowEmpty’=>true,‘on’ => ‘upload’),[/color]

        array('email', 'length', 'max' =&gt; 50),


        array('address', 'safe'),


        // The following rule is used by search().


        // Please remove those attributes that should not be searched.


        array('id, full_name, designation_id, department_id, contact_no, email, address, id_no', 'safe', 'on' =&gt; 'search'),


    );


}

Please any one help me.