Example #1
0
 /**
  * загражает файл аватарки и создает миниатюру для него
  * @return bool
  */
 public function uploadFoto()
 {
     $photo = UploadedFile::getInstance($this, 'photo');
     //echo'<pre>';print_r($photo);echo'</pre>';die;
     if ($photo && $photo->tempName) {
         $this->photo = $photo;
         //echo'<pre>';print_r($this->photo);echo'</pre>';//die;
         //$img_path = $this->photo->tempName . DIRECTORY_SEPARATOR . $this->photo->name;
         //echo'<pre>';var_dump($this->validate());echo'</pre>';//die;
         //echo'<pre>';print_r($this);echo'</pre>';die;
         if ($this->validate()) {
             //echo'<pre>';print_r($this->image);echo'</pre>';die;
             $filename = DStringHelper::buildFileName($this->photo->name);
             $path = $this->avatarsPath;
             $tmp_path = Yii::getAlias('@frontend') . DIRECTORY_SEPARATOR . 'web' . DIRECTORY_SEPARATOR . 'tmp';
             $tmp_file = $tmp_path . DIRECTORY_SEPARATOR . $filename;
             $this->photo->saveAs($tmp_file);
             //загружаем картинку
             $img = new SimpleImage();
             $img->load($tmp_file);
             //получаем информацию по изображению
             $original_info = $img->get_original_info();
             //echo'<pre>';print_r($original_info);echo'</pre>';die;
             if ($original_info['orientation'] != 'square') {
                 Yii::$app->session->setFlash('error', 'К загрузке допускаются только квадратные фото');
                 unlink($tmp_file);
                 return false;
             } else {
                 //если было прикреплено фото - то удаляем его
                 if ($this->foto != '') {
                     $this->deleteImageFiles();
                 }
                 // перемещаем фото из временного каталога
                 rename($tmp_file, $path . DIRECTORY_SEPARATOR . $filename);
             }
             //$this->photo->saveAs( $path . DIRECTORY_SEPARATOR . $filename);
             $this->foto = $filename;
             //echo'<pre>';print_r($path . DIRECTORY_SEPARATOR . $filename);echo'</pre>';die;
             DImageHelper::createTmb($path, $filename, Yii::$app->params['poker-tmb-image-res']['width'], Yii::$app->params['poker-tmb-image-res']['height']);
             $this->photo = null;
         } else {
             Yii::$app->session->setFlash('error', 'Ошибка загрузки фото');
             return false;
         }
     }
     return true;
 }
Example #2
0
 public function beforeValidate()
 {
     if (isset($this->alias)) {
         if ($this->alias == '') {
             $this->alias = DStringHelper::buildAlias($this->name);
         }
         //echo'<pre>';var_dump($this->aliasIsUnique);echo'<pre>';die;
         //echo'<pre>';print_r($this);echo'<pre>';die;
         if ($this->aliasIsUnique === false) {
             $this->alias .= '-' . time();
         }
     }
     return parent::beforeValidate();
 }
Example #3
0
 protected function uploadFoto($model)
 {
     $photo = UploadedFile::getInstance($model, 'photo');
     if ($photo && $photo->tempName) {
         $model->photo = $photo;
         if ($model->validate()) {
             $path = Yii::getAlias('@frontend') . '/web/files/pages/';
             echo '<pre>';
             print_r($model->photo->extension);
             echo '</pre>';
             //die;
             echo '<pre>';
             print_r($model->photo->name);
             echo '</pre>';
             //die;
             $filename = DStringHelper::buildFileName($model->photo->name);
             //$filename = $path . $filename;
             //$filename = DStringHelper::buildFileName($path, $model->photo->extension) . '.' . $model->photo->extension;
             //echo'<pre>';print_r($filename);echo'</pre>';die;
             $model->photo->saveAs($path . $filename);
             $model->image = $filename;
             $model->photo = null;
         }
     }
     return $model;
 }
Example #4
0
 public function beforeValidate()
 {
     $this->password = DStringHelper::generate_password(7);
     $date_str = $this->birth_day . '-' . $this->birth_month . '-' . $this->birth_year;
     //13-07-2015
     $this->birthday = DDateTimeHelper::DateToUnix($date_str);
     //		$date_str = '02-01-1996';
     //		echo'<pre>';print_r($date_str);echo'</pre>';//die;
     //		echo'<pre>';print_r($this->birthday);echo'</pre>';//die;
     //		$this->birthday = DDateTimeHelper::DateToUnix($date_str, '', 2);
     //		echo'<pre>';print_r($this->birthday);echo'</pre>';//die;
     //		echo'<pre>';print_r(date('d-m-y', $this->birthday));echo'</pre>';die;
     return parent::beforeValidate();
 }