rename file and update path

Hello everyone,

I have a form where to create a file: Database record + upload file.

my form : view


<?php echo $form->textFieldRow($model, 'file_name', array('class' => 'span5', 'maxlength' => 255)); ?>

<?php $currentaction = $this->getAction()->getId(); 

if ($currentaction == 'create') {

    echo $form->fileFieldRow($model, 'uploaded_file', array('class' => 'span5'));





Controller :

public function actionCreate(){


 $model->uploaded_file = CUploadedFile::getInstance($model, 'uploaded_file');

 $model->original_file_name = $model->uploaded_file->getName();

 $model->extension = $model->uploaded_file->getExtensionName();

  $model->file_size = $model->uploaded_file->getSize();




 protected function afterSave() {


  $this->path = $this->createFilePath(); // The path of the file exemple c:/files/nameFile.doc


All this work fine, The file uploaded to the server named whatever we enter in the form and the path is right.

My problem is with UPDATING!

How can I update the the file name, and Automatically, the physical file will be renamed and the database record path field will be updated

Thank you

For anyone who is interested I have found a solution:

 protected function beforeSave(){ 


 $this->oldModel= self::model()->findByPk($this->id);       






        $this->path = E_STORAGE_PATH_FI . '/files/' . $new_name . "." . $extenion;

        rename ( $old_path,  $this->path);



Hope the forum become more active though :)