gpt4 book ai didi

php - Yii2:无法打开流:没有那个文件或目录

转载 作者:搜寻专家 更新时间:2023-10-31 21:22:17 25 4
gpt4 key购买 nike

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

我的更新函数:

    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,
]);
}
}

还有我的 params.php 文件:

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

];

当我在表单中上传文件时出现此错误:

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

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

最佳答案

 $uploadDir = Yii::getAlias('@web/web/uploads') . Yii::getAlias('@web/web/uploads');

替换为

 $uploadDir = Yii::getAlias('@web/web/uploads');

关于php - Yii2:无法打开流:没有那个文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44283263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com