コード例 #1
0
 public function actionIndex($id)
 {
     $model = new ArquivoCrm();
     $file = UploadFile::load($model, 'file');
     if (!empty($file->name)) {
         $name = $this->Formart($file->name);
         $model->name = $name;
         $model->name_alias = $file->name;
         $model->size = $file->size;
         $model->type = $file->type;
         $model->cliente_crm_id = $id;
         $file->saveAs($this->dirName() . $name);
         $model->save();
         $this->Json(['name' => $file->name, 'url' => $this->createUrl('app/assets/arquivos/') . $name, 'delete' => $this->createUrl('painel/arquivos/delete/' . $model->id . '/' . $id)]);
     } else {
         return $this->render('index', ['id' => $id, 'model' => $model, 'dataProvider' => ArquivoCrm::dataProvider($id)]);
     }
 }
コード例 #2
0
 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]]]);
 }