I am trying to save my uploaded file with a new name, so I must update the file attribute again to give it the new name to avoid the mismatching between the file name in the db and the name of the real file in my directory.
But the file attribute type is file, so I'll get an error saying please upload a file
every time I do this process, here is my create
action code:
if(isset($_POST['Customers'])) {
$model->attributes=$_POST['Customers'];
$model->image = UploadedFile::getInstance($model, 'image');
if($model->save()){
$model->image->saveAs(getcwd()."/images/customers/CUST-".$model->id."-".$model->image);
$model->image = "CUST-".$model->id."-".$model->image;
if($model->save())
return $this->redirect(['view', 'id' => $model->id]);
}
}