Yii1 Form in modal popup. Input e upload immagini

Salve,
ho creato un form che si apre in modal popup. In questo form l’ utente può scrivere un messaggio e caricare le immagini. Poi il tutto viene salvato in 2 diverse tabelle nel database tramite 2 model diversi.
Il messaggio viene salvato in una tabella e l’ immagine in un’ altra tabella.
Per quanto riguarda il salvataggio del messaggio il tutto procede bene e il messaggio viene salvato correttamente. Ho un problema con il salvataggio delle immaggini. Non vengono salvate.
Questo è il mio codice.
Nel layout ho il link che apre il form in modal popup e la funzione:

<?php echo CHtml::link('Scrivi Post', "",
     array(
	 'style'=>'color:#000000; padding-bottom:0px !important; margin-bottom:0px !important;',
         'onclick'=>"{
            newPost();
            $('#dialogPost').dialog('open');
         }"
     ));
?>

<script>
//FUNZIONE PER APRIRE IL FORM POST IN MODAL
function newPost()
{
    <?php echo CHtml::ajax(array(
            'url'=>array('Post/Create'), //path to controller action we created above
            'data'=> "js:$(this).serialize()",
            'type'=>'post',
            'dataType'=>'json',
            'success'=>"function(data)
            {
                if (data.status == 'failure')
                {
                    $('#dialogPost div.divNewPost').html(data.div);
                    $('#dialogPost div.divNewPost form').submit(newPost);
                }
                else
                {
                    $('#V div.divNewPost').html(data.flash);
                    setTimeout(\"$('#dialogPost').dialog('close') \",3000);
                }
            } ",
    ))?>;
    return false; 
}
</script>

Questa e il codice della view del form che viene renderizzata form

<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id'=>'post-form',
    'type'=>'horizontal',
	'method' =>'POST',
    //'action'=> Yii::app()->createUrl('/Userphoto/NewPhoto'),
	'htmlOptions'=>array(
'enctype'=> 'multipart/form-data',
),
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>
<div class="form" style="min-width:70%; text-align:center; margin:auto;">

<div class="divcamposingolo">
	<div class="row">		
	<?php
  $this->widget('CMultiFileUpload', array(
     'model'=>$userphoto,
     'attribute'=>'images',
     'accept'=>'jpg|png',
	 //'name'=>'Userphoto_images[]',
     'options'=>array(
	 'htmlOptions' => array('multiple' => 'multiple','id'=>'images'),
	 'afterFileAppend'=>'function(e, v, m){
     /*$(".MultiFile-title:last").remove();*/
     var fileReader = new FileReader();
     fileReader.readAsDataURL(e.files[0]);
     fileReader.onload = function(){	 
     $(".MultiFile-remove:last").before("<span class=pip><img class=imageThumb><span class=remove></span></span>");
     $(".MultiFile-label:last img").attr("src", fileReader.result);
     }
     }',
     //'onFileSelect'=>'function(e, v, m){ alert("onFileSelect - "+v) }',
     //'afterFileSelect'=>'function(e, v, m){ alert("afterFileSelect - "+v) }',
     //'onFileAppend'=>'function(e, v, m){ alert("onFileAppend - "+v) }',
     //'afterFileAppend'=>'function(e, v, m){ alert("afterFileAppend - "+v) }',
     //'onFileRemove'=>'function(e, v, m){ alert("onFileRemove - "+v) }',
    // 'afterFileRemove'=>'function(e, v, m){ alert("afterFileRemove - "+v) }',
     ),
     'denied'=>'Formati permessi jpg|png',
     'max'=>10, // max 10 files
  ));
?>
<?php echo $form->error($userphoto,'images'); ?>
</div>
</div>
<div class="divisoreverde">
			<div id="img">
			</div>
			</div>

	<div class="divcamposingolo">
	<div class="row">
		<?php echo $form->labelEx($model,'privacy'); ?>
		<?php 
		$opzioni = array('1'=>'Tutti (chiunque su Jummix)','2'=>'Amici (solo i tuoi Amici)','3'=>'Solo Tu (Solo tu puoi leggere il contenuto)');
		echo $form->dropDownList($model,'privacy', $opzioni, array('style'=>'width:50%;', 'id'=>'privacy'));?>
		<?php echo $form->error($model,'privacy'); ?>
	</div>
	</div>

	<div class="divcamposingolo">
	<div class="profile-userpic" style="width:10%; display:inline-block;">
	<?php echo User::TumbPhotoProfilo();?>
	</div>
	<div class="row" style="width:90%;display:inline-block;">
	<?php echo $form->hiddenField($model,'userid',array('value'=>Yii::app()->user->id)); ?>
	<?php echo $form->hiddenField($model,'approve',array('value'=>Yii::app()->user->postaprove)); ?>
		<?php /*echo $form->labelEx($model,'message'); */?>
		<?php echo $form->textArea($model,'message',array('style'=>'width:90%;','maxlength'=>5000,'placeholder'=>'A cosa stai pensando '.Yii::app()->user->nome.'?')); ?>
		<?php echo $form->error($model,'message'); ?>
	</div>
	</div>
	
	<div class="divcamposingolo">
	<div class="row">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Conferma' : 'Save',array('class'=>'btn btn-primary btn-small')); ?>
		<?php $this->endWidget(); ?>
	</div>
	</div>

</div><!-- form -->

Questa è invece la mia action nel Controller Post (l’ url che viene richiamato nella funzione Post/Create )

public function actionCreate()
	{
		$model=new Post;
		$userphoto=new Userphoto;
		$userphoto->scenario='ChargePhotos';
		$type = isset($_GET['type']) ? $_GET['type'] : 'post';
		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['Post']))
		{
			$userId = Yii::app()->user->id;
			$Utente = User::model()->findByAttributes(array('id'=>Yii::app()->user->id));
			$model->attributes=$_POST['Post'];
			$model->date = date('Y-m-d');
			$model->time = date('G:i:s');
			$model->notify = $Utente->cognome.' '.$Utente->nome.' ha pubblicato qualcosa';
			
			if($model->save())
            {
			$userphoto->attributes = $_POST['Userphoto'];
			$photos = CUploadedFile::getInstancesByName('Userphoto[images]');
			if (isset($photos) && count($photos) > 0) {	
			$photos = CUploadedFile::getInstancesByName('Userphoto[images]');
            // proceed if the images have been set
            foreach ($photos as $image => $pic) {
	        $nomeFile=str_replace(" ","",$pic->name);
            //echo $pic->name.'<br />';
	        $create_link = Yii::app()->createAbsoluteUrl('').'/user-foto/'.$userId.'/'.$nomeFile;
	        $path = Yii::getPathOfAlias('webroot').'/user-foto/'.$userId.'/';		
	        //SE NON ESISTE LA directory LA CREIAMO
	        if(!is_dir($path))
	        {
	        mkdir($path, 0, true);	
	        chmod($path, 0755);
	        }
			//  if ($pic->saveAs($path.$pic->name)) {
			if ($pic->saveAs($path.'/'.$nomeFile))
			{
			// add it to the main model now
            $img_add = new Userphoto();
            $img_add->images = $nomeFile; //it might be $img_add->name for you, filename is just what I chose to call it in my model
            $img_add->userid = Yii::app()->user->id;
			$img_add->postid = $model->id;
			$img_add->link = $create_link; // this links your picture model to the main model (like your user, or profile model)
			$img_add->cartella = '/user-foto/'.$userId.'/';
			$img_add->date = $date;
 
            $img_add->save(); // DONE
            }
            else
			{
                echo 'Immagine/i non caricata/e!';
            }
			}
			}


	$this->redirect(array('/User/DashBoard'));
               echo CJSON::encode(array(
                    'status'=>'success', 
                    'flash'=>"Post creato correttamente.", 
                    ));
               exit;              
            }
		}

		echo CJSON::encode(array(
             'status'=>'failure', 
             'div'=>$this->renderPartial('create', array('model'=>$model,'userphoto'=>$userphoto), true)
             ));
        exit; 
	}

Il mio problema è che non riesco ne a inserire i dati dell immagine nella tabella del database ne a salvare le immagini scelte nella directory. Qualcuno è cosi gentile da potermi aiutare? Grazie in anticipo.

this question should be move to Yii1 section

Nessuno può aiutarmi per favore? Grazie