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();
...
}
Model
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