在yii2中更新上载的文件

在yii2中更新上载的文件,yii2,Yii2,我用下面的方法上传图片并保存在服务器上。现在我想写一个控制器来更新上传的图像。有什么想法吗 控制器 public function actionCreate() { $model = new DoctorTbl(); if ($model->load(Yii::$app->request->post()) ) { $image = UploadedFile::getInstance($model, 'd_img_path');

我用下面的方法上传图片并保存在服务器上。现在我想写一个控制器来更新上传的图像。有什么想法吗

控制器

    public function actionCreate()
    {
    $model = new DoctorTbl();

    if ($model->load(Yii::$app->request->post()) ) {

        $image = UploadedFile::getInstance($model, 'd_img_path');

        $model->d_img_path= $model->d_nic.'.'.$image->extension;

        if ($model->save()) {
            $image->saveAs( 'uploads/'.$model->d_img_path);

            return $this->redirect(['view', 'id' => $model->d_id]);


        }


    } else {
        return $this->render('create', [
            'model' => $model,
        ]);
    }
}
public function Update($id)
{
 $model = $this->findModel($id);
 $oldImage = $model->d_img_path;
 if ($model->load(Yii::$app->request->post()))
 {
    $image = UploadedFile::getInstance($model, 'd_img_path');
    if(isset($image)){
        $model->d_img_path=  $model->d_nic.'.'.$image->extension;
    } else {
        $model->d_img_path = $oldImage;
    }
    if($model->save())
    {
        if(isset($image)){
            $image->saveAs('uploads/'.$model->d_img_path);   
        }
    }
    return $this->redirect('view');
}    
}