Hi
I need your help
I have a problem with saving multiple files into a database
Here is my code
public function actionUpload(){
$model = new Galimg();
if (Yii::$app->request->isPost) {
$model->load(Yii::$app->request->post());
$img = UploadedFile::getInstances($model, 'img');
if ($model->validate()) {
foreach ($img as $file) {
$sfile = Yii::$app->security->generateRandomString() . '.' . $file->extension;
$model->img = $sfile;
$model->isNewRecord = true;
if( $model->save()){
$file->saveAs('uploads/galeria/' . $sfile);
}
}
}
return $this->redirect(['galeria/admin']);
}else {
return $this->render('upload', [
'model' => $model,
]);
}
}
files are copied correctly but the database is stored only the last file