public function updateThumbImage() { if ($this->thumb_key !== 'style_default') { //Удаляем старый стиль $file_thumb_path = UserUrl::styleThumb(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($this->thumb_key, UserUrl::IMAGE_THUMB); if (file_exists($file_thumb_path)) { unlink($file_thumb_path); } $file_orig_path = UserUrl::styleThumb(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($this->thumb_key, UserUrl::IMAGE_ORIGINAL); if (file_exists($file_orig_path)) { unlink($file_orig_path); } } $file = UploadedFile::getInstance($this, 'photo'); if ($file) { if ($file->size !== 0) { $file_id = AlphaId::id(rand(10000000000, 9999999999999)); $file_path = UserUrl::styleThumb(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL); $file->saveAs($file_path); $image = Yii::$app->image->load($file_path); $type = Yii\image\drivers\Image::NONE; $file_thumb_path = UserUrl::styleThumb(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_THUMB); $image->resize(70, 70, $type); $image->save($file_thumb_path); $this->thumb_key = $file_id; if (!$this->save()) { $result = ['error' => ['msg' => Yii::t('app', 'Ошибка записи в базу-данных')]]; } else { $result = ['response' => ['status' => true, 'thumb_key' => $file_id, 'thumb_url' => UserUrl::styleThumb(true, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_THUMB)]]; } } else { $result = ['error' => ['msg' => Yii::t('app', 'Данные не получены')]]; } } else { $result = ['error' => ['msg' => Yii::t('app', 'Данные не получены')]]; } return $result; }
</div> <div class="col-md-1"> <div class="row"> <div class="col-md-12"> <?php if ($style->thumb_key == 'style_default' || $style->thumb_key == 'default_style_thumb' || empty($style->thumb_key)) { ?> <img class="style-min-thumb pull-right" src="/images/style_default.jpg"/> <?php } else { ?> <img class="style-min-thumb pull-right" src="<?php echo UserUrl::styleThumb(true, $style->id) . '/' . UserUrl::imageFile($style->thumb_key, UserUrl::IMAGE_THUMB); ?> "/> <?php } ?> </div> </div> <div class="row"> <div class="col-md-12"> <form enctype="multipart/form-data" action="<?php echo Url::toRoute(['styles-api/upload-thumb', 'id' => $style->id]); ?> "> <span class="btn btn-link button-1-line turn-on-editable pull-right fileinput-button">