Hello. How can i generate the link of the uploaded files and store it in db separated by commas.
public function actionCreate()
{
$model = new Consum();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->file = UploadedFile::getInstances($model, 'file');
if (!is_dir(Yii::getAlias('webroot') .'/uploads/report/'. $model->consum . '/' . date('Y-m-d'))) {
mkdir(Yii::getAlias('webroot') . '/uploads/report/' . $model->consum . '/' . date('Y-m-d'), 0644, true);
}
//mkdir(Yii::getAlias('webroot') .'/uploads/report/'. $model->consum, 0644, true);
if ($model->file && $model->validate()) {
foreach ($model->file as $file) {
$file->saveAs(Yii::getAlias('webroot').'/uploads/report/' . $model->consum . '/' . date('Y-m-d') . '/' . $file->baseName . '-' . date('Y-m-d') . '-' . $model->consum . '.' . $file->extension);
}
}
return $this->redirect(['view', 'id' => $model->consum_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->consum_id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
I’m able to upload the files correctly but i cant manage to generate the url’s for them