Search the Community
Showing results for tags 'cuploadedfile'.
Found 1 result
Hi Larry, on page 216 of your Yii book, you describe how to rename an uploaded file using the $model->id of the User model. I think this is a good idea, but I don't see how your code can work without an afterSave or something. Here is your code: $model->avatar->saveAs($dest . '/' . $model->id . '.' . $model->avatar->extensionName); The line above would have to come after the code to save the model: if ($model->save()) because you don't obtain the $model->id until after you save it. But since you've already saved the file's name to the database, the filename in the database and the name of the uploaded file don't match. And you should'nt save the uploaded file in the file system until you know that the save to the database was successful. Do you see what I mean? Am I missing something? Larry Z.