Answer the question
In order to leave comments, you need to log in
How to pass filename from controller to model?
The controller is described as follows
if (Yii::$app->request->isPost) {
$model->file = UploadedFile::getInstance($model, 'file');
if ($model->file && $model->validate()) {
$model->file->saveAs($model->file);
Answer the question
In order to leave comments, you need to log in
$path = 'some/path/'
$model = new SomeModel();
$file = UploadedFile::getInstance($model, 'file');
if ($model->file && $model->validate()) {
$file->saveAs($path.$file->baseName);
$model->filename = $file->baseName;
$model->save();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question