3
我有Yii2框架中的上傳/更新功能問題。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
誰能幫我... thank`s!
任一路徑問題或文件夾的權限(077)的問題。錯誤表示存在路徑問題 –
希望它能正常工作, '@projectImgUrl'=>'@web /'返回[ 'aliases'=> [0] [@projectImgPath'=>'webroot/web/uploads' ]' 相同 $ uploadDir = Yii :: getAlias('@ web/uploads')。警予:: getAlias( '@網/上傳'); $ uploadPath = Yii :: getAlias('@ web/uploads'); –
你好,先生! 現在我的代碼是: '@projectImgPath'=> '@ Webroot公司/網絡/上傳', '@projectImgUrl'=> '@網/', ------------ ----------------------- $ uploadDir = Yii :: getAlias('@ web/uploads').Yii :: getAlias('@ web /上傳); $ uploadPath = Yii :: getAlias('@ web/uploads'); 但是又不起作用... –