2
..\frontend\web\uploads
を作成しました。 uploads
が存在しているとき、それは動作しますYii2でフォルダを作成して画像をアップロードする
public function actionCreate()
{
$model = new Properties();
$date = date('YmdHis');
if ($model->load(Yii::$app->request->post())) {
$file = \yii\web\UploadedFile::getInstance($model, 'url_img');
if (!empty($file))
$model->url_img = $date.$file;
if($model->save())
{
if (!empty($file))
$file->saveAs(Yii::getAlias('@frontend') .'/web/uploads/'.$date.$file);
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', ['model' => $model]);
} else {
return $this->render('create', ['model' => $model]);
}
}
:
これは私が持っているPropertiesControllers.php
構成で機能Create
です。しかし、私は../web/uploads/img
が存在していないので、それはエラーが表示さuploads
if (!empty($file))
$file->saveAs(Yii::getAlias('@frontend') .'/web/uploads/img'.$date.$file);
uploads\img
ように新しいフォルダにリダイレクトします。
この問題は解決できません。助けて!
、ありがとうございます。 – user3318842
嬉しいことです。投稿が役立つ場合は、回答を承認済みとしてマークしてください –