public function runAction($action, $data)
 {
     Yii::log('ACTION CALLED - action is: ' . $action, 'info');
     $vars = unserialize($data);
     $this->allowedExtensions = $vars['allowedExtensions'];
     $this->sizeLimit = (int) $vars['sizeLimit'];
     $this->uploadDir = $vars['uploadDir'];
     $this->receptorClassName = $vars['receptorClassName'];
     $this->methodName = $vars['methodName'];
     $this->userdata = $vars['userdata'];
     $this->tipoFoto = $vars['tipoFoto'];
     if ($this->allowedExtensions == null || $this->allowedExtensions == '') {
         $this->allowedExtensions = array();
     }
     Yii::log('ACTION CALLED - data is: ' . CJSON::encode($vars), 'info');
     if ($action == 'upload') {
         $uploader = new ValumsFileUploader($this->allowedExtensions, $this->sizeLimit);
         if ($uploader->checkServerSettings() != null) {
             Yii::log("CocoWidget. Please increase post_max_size and upload_max_filesize to " . $this->sizeLimit, "error");
             return;
         }
         // ensure directory
         $this->uploadDir = rtrim($this->uploadDir, '/') . '/';
         @mkdir($this->uploadDir);
         $result = $uploader->handleUpload($this->uploadDir);
         if (isset($result['success'])) {
             if ($result['success'] == true) {
                 //Guardar en la base de datos
                 //$model=new Archivo;
                 //$model->id_correspondencia = 2;
                 //$model->nombre = "Hola";
                 //$model->fecha = date("d-m-Y H:i:s");
                 //if($model->save())
                 //	{	}
                 Yii::log('ACTION CALLED - RESULT=SUCCESS', 'info');
                 $fullpath = $result['fullpath'];
                 $fullpath = trim($fullpath);
                 /*Yii::app()->user->setFlash('success',".".$fullpath."  -  ".$this->userdata.".");	*/
                 $this->onFileUploaded($fullpath, $this->userdata, $this->tipoFoto);
             } else {
                 Yii::log('ACTION CALLED - RESULT=ERROR1', 'info');
             }
         } else {
             Yii::log('ACTION CALLED - RESULT=ERROR2', 'info');
         }
         echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     }
 }
Exemple #2
0
 public function runAction($action, $data)
 {
     Yii::log('ACTION CALLED - action is: ' . $action, 'info');
     $vars = unserialize($data);
     $this->allowedExtensions = $vars['allowedExtensions'];
     $this->sizeLimit = (int) $vars['sizeLimit'];
     $this->uploadDir = $vars['uploadDir'];
     $this->receptorClassName = $vars['receptorClassName'];
     $this->methodName = $vars['methodName'];
     $this->userdata = $vars['userdata'];
     if ($this->allowedExtensions == null || $this->allowedExtensions == '') {
         $this->allowedExtensions = array();
     }
     Yii::log('ACTION CALLED - data is: ' . CJSON::encode($vars), 'info');
     if ($action == 'upload') {
         $uploader = new ValumsFileUploader($this->allowedExtensions, $this->sizeLimit);
         if ($uploader->checkServerSettings() != null) {
             Yii::log("CocoWidget. Please increase post_max_size and upload_max_filesize to " . $this->sizeLimit, "error");
             return;
         }
         // ensure directory
         $this->uploadDir = rtrim($this->uploadDir, '/') . '/';
         @mkdir($this->uploadDir);
         $result = $uploader->handleUpload($this->uploadDir, $this->nombrealt, false);
         if (isset($result['success'])) {
             if ($result['success'] == true) {
                 Yii::log('ACTION CALLED - RESULT=SUCCESS', 'info');
                 $fullpath = $result['fullpath'];
                 $this->onFileUploaded($fullpath, $this->userdata);
             } else {
                 Yii::log('ACTION CALLED - RESULT=ERROR1', 'info');
             }
         } else {
             Yii::log('ACTION CALLED - RESULT=ERROR2', 'info');
         }
         echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     }
 }