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

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 !

  • 写回答

1条回答 默认 最新

  • doufan6886 2017-06-22 12:08
    关注
     $uploadDir = Yii::getAlias('@web/web/uploads') . Yii::getAlias('@web/web/uploads');
    

    replace with

     $uploadDir = Yii::getAlias('@web/web/uploads');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签)
  • ¥50 sft下载大文阻塞卡死
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失
  • ¥15 springboot+vue 集成keycloak sso到阿里云
  • ¥15 win7系统进入桌面过一秒后突然黑屏
  • ¥30 backtrader对于期货交易的现金和资产计算的问题
  • ¥15 求C# .net4.8小报表工具
  • ¥15 安装虚拟机时出现问题