/** * Updates an existing Section model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $section = section::find()->where(['id' => $id])->one(); $section_ru = section_ru::find()->where(['section_id' => $id])->one(); $section_en = section_en::find()->where(['section_id' => $id])->one(); if (!empty(UploadedFile::getInstances($section, 'images'))) { if ($section->load(Yii::$app->request->post())) { if (file_exists($path = getcwd() . '\\..\\..' . $section->photo_path)) { unlink($path); } if (file_exists($path = getcwd() . '\\..\\..' . $section->photo_path427320)) { unlink($path); } $images = UploadedFile::getInstances($section, 'images'); $newFileName = date("YmdHis"); $filePath = Yii::getAlias('@frontend') . '/web/uploads/' . $newFileName . '.' . $images[0]->extension; $file427320 = Yii::getAlias('@frontend') . '/web/uploads/427320/' . $newFileName . '.' . $images[0]->extension; $images[0]->saveAs($filePath); Image::thumbnail($filePath, 427, 320)->save($file427320, ['quality' => 50]); $section->photo_path = Yii::getAlias('@resource') . '/uploads/' . $newFileName . '.' . $images[0]->extension; $section->photo_path427320 = Yii::getAlias('@resource') . '/uploads/427320/' . $newFileName . '.' . $images[0]->extension; } } if ($section_ru->load(Yii::$app->request->post()) && $section_en->load(Yii::$app->request->post()) && $section->save()) { $section_ru->save(); $section_en->save(); return $this->redirect(['update', 'id' => $section->id]); } else { return $this->render('update', ['section' => $section, 'section_ru' => $section_ru, 'section_en' => $section_en]); } }