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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下