我想将我的图像保存在db中,但它已上传但未保存在我的数据库中任何人都知道如何解决此问题
public function actionUpdate($id) {
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) {
$fname = UploadedFile::getInstance($model, 'imageFile');
if (!empty($fname)) {
$temp_path = Yii::$app->basePath . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR;
$model->save();
$fname->saveAs($temp_path . $fname);
$model->imageFile = $fname->name;
// echo '<pre>'; print_r($fname->name);
//exit();
}
if ($model->save()) { // To save the title to the database
Yii::$app->getSession()->addFlash('success', 'Image uploaded');
return $this->redirect(['index']);
}
} else {
return $this->render('update', [
'model' => $model,
]);
}
}