How to change file name before saveing it to DB


I’m looking for some way to change file name before saving it to database. I know how to change file name using saveAs(), but I’d like to change file name in DB as well. Here is my code for create action:


	 * Creates a new model.

	 * If creation is successful, the browser will be redirected to the 'view' page.


	public function actionCreate()


		$model=new Company;

		// Uncomment the following line if AJAX validation is needed

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



			$folder=Yii::getPathOfAlias('webroot').'/images/company/';// folder for uploaded files











							$model->logo->saveAs($folder . $model->id . '/'.$model->id .'_'.$model->update_time.'_'.$model->logo);









in this case my file name is: $model->id .’’.$model->update_time.’’.$model->logo, so lets say 1_123456789_file.jpg, but to database only file.jpg is written. Any hints how to change my controller to change file name before save. I’ve been looking around for solution, but couldn’t find.

Regards lukBB

Use a temporary variable for CUploadedFile::getInstance($model,‘logo’);… and assign the file name you need to the $model->logo…

something like




To save with the same name use:


Thank you mdomba, all work great!!