Beispiel #1
0
 public static function create($config = [])
 {
     if (!empty($config)) {
         if (!empty($config['tmpName'])) {
             $dirName = $config['dirName'];
             $rensize = WideImage::load($config['tmpName']);
             self::dir($dirName);
             chmod($dirName, 0777);
             $big = WWW_ROOT . '/images/' . $dirName . '/big/' . $config['name'];
             $small = WWW_ROOT . '/images/' . $dirName . '/small/' . $config['name'];
             $im = imagecreatefromstring($rensize->resize(370, 281));
             imagejpeg($im, $small);
             $imb = imagecreatefromstring($rensize->resize(767, 511));
             imagejpeg($imb, $big);
             chmod($small, 0777);
             chmod($big, 0777);
         }
     } else {
         return '';
     }
 }
 public function actionUpload()
 {
     $model = $this->findModel();
     $file = UploadFile::load($model, 'file');
     if (empty($file)) {
         throw new Exception("Error Processing Request", 401);
     }
     $widimage = WideImage::load($file->tmpName);
     $name = $model->nome . '-' . $model->id . '.' . $file->typeName;
     $resize = $widimage->resize(255, 255);
     //verificando se existe foto
     $fileName = static::dir() . $model->file;
     if (file_exists($fileName)) {
         unlink($fileName);
     }
     $filename = static::dir() . $name;
     $resize->saveToFile($filename);
     $model->file = $name;
     $model->save();
     chmod($filename, 0777);
     Session::setSession(['photo' => $model->file]);
     $this->Json(['files' => [['url' => $this->createUrl() . '/app/assets/arquivos/profile/' . $model->file]]]);
 }