dtg78700
2017-05-31 11:12
浏览 156
已采纳

Yii2:无法打开流:没有这样的文件或目录

i have problem with my upload/update function in Yii2 framework.

My update function:

    public function actionUpdate($id) {
    $model = $this->findModel($id);
    //        $model->scenario = 'update';

    if ($model->load(Yii::$app->request->post()) && $model->save()) {
        $uploadDir = Yii::getAlias('@web/web/uploads') . Yii::getAlias('@web/web/uploads');
        $uploadPath = Yii::getAlias('@web/web/uploads');

        $model->save();
        $imageProject = $model->id;

        //Main Image
        $image = UploadedFile::getInstance($model, 'main_image');

        if ($image) {
            $imgProject = 'project_' . $imageProject . '.' . $image->getExtension();
            $image->saveAs($uploadDir . '/' . $imgProject);
            $model->main_image = $uploadPath . '/' . $imgProject;
        }

        if ($model->upload()) {
            $model->save();

            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    } else {
        return $this->render('update', [
            'model' => $model,
        ]);
    }
}

And my params.php file :

return [
'aliases' => [
    '@projectImgPath' => '@webroot/web/uploads',
    '@projectImgUrl' => '@web/web/'
]

];

When i upload file in my form i have this error:

move_uploaded_file(/web/uploads/web/uploads/gallery_1_3.png): failed to open stream: No such file or directory

Anyone can help me... thank`s !

图片转代码服务由CSDN问答提供 功能建议

我在Yii2框架中的上传/更新功能有问题。

我的更新功能:

  public function actionUpdate($ id){
 $ model = $ this-> findModel($ id); 
 // $ model-&gt  ; scenario ='update'; 
 
 if if($ model-> load(Yii :: $ app-> request-> post())&& $ model-> save()){  
 $ uploadDir = Yii :: getAlias('@ web / web / uploads')。  Yii :: getAlias('@ web / web / uploads'); 
 $ uploadPath = Yii :: getAlias('@ web / web / uploads'); 
 
 $ model-> save(); 
  $ imageProject = $ model-> id; 
 
 //主图像
 $ image = UploadedFile :: getInstance($ model,'main_image'); 
 
 if($ image){
 $ imgProject  ='project_'。  $ imageProject。  ''  。  $ image-> getExtension(); 
 $ image-> saveAs($ uploadDir。'/'。$ imgProject); 
 $ model-> main_image = $ uploadPath。  '/'。  $ imgProject; 
} 
 
 if($ model-> upload()){
 $ model-> save(); 
 
返回$ this-> redirect(['view',  'id'=> $ model-> id]); 
} else {
返回$ this-> render('update',[
'model'=> $ model,
])  ; 
} 
}其他{
返回$ this-> render('update',[
'model'=> $ model,
]); 
} 
} 
   
 
 

我的params.php文件:

 返回[
'aliases'=>  [
'@ projectImgPath'=>  '@ webroot / web / uploads',
'@ projectImgUrl'=>  '@ web / web /'
] 
   
 
 

];

当我在表单中上传文件时,我有这个 错误:

  move_uploaded_file(/web/uploads/web/uploads/gallery_1_3.png):无法打开流:没有这样的文件或目录
   
 
 

任何人都可以帮助我......谢谢!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题