/**
  * Sube al servidor el archivo de plantilla a la carpeta
  * docs/docsXXX/circulares/plantillas.
  * 
  * Debe existir la carpeta docs/docsXXX/circulares.
  * Se sube usando ftp.
  * 
  * @return type
  */
 public function SubirPlantillaAction()
 {
     $fichero = $this->request['FILES']['filePlantilla'];
     if (in_array($fichero['type'], $this->tiposPermitidos)) {
         $carpetaPlantillas = $_SESSION['appPath'] . "/docs/docs{$_SESSION['emp']}/circulares/plantillas";
         Archivo::creaCarpeta($carpetaPlantillas);
         if (is_uploaded_file($fichero['tmp_name'])) {
             $ftp = new Ftp($_SESSION['project']['ftp']);
             if ($ftp) {
                 $ok = $ftp->upLoad($carpetaPlantillas, $fichero['tmp_name'], $fichero['name']);
                 $this->_errores = $ftp->getErrores();
                 $ftp->close();
             } else {
                 $this->_errores[] = "Fallo al conectar vía FTP";
                 foreach ($_SESSION['project']['ftp'] as $item) {
                     $this->_errores[] = $item;
                 }
             }
         }
     } else {
         $this->_errores[] = "Tipo de archivo no permitido. Sólo se admiten archivos rtf,txt y html";
     }
     $this->values['errores'] = $this->_errores;
     return $this->IndexAction();
 }
Exemple #2
0
 /**
  * Sube el documento indicado en $this->_ArrayDoc al servidor via FTP
  *
  * Si es una imagen, la redimensiona se han establecido dimensiones
  * fijas en $this->_ArrayDoc['width'] y $this->_ArrayDoc['heigth']
  *
  * @return boolean TRUE si se subió con éxito
  */
 private function subeDocumento()
 {
     $pathInfo = pathinfo($this->PathName);
     $carpetaDestino = $this->_prePath . $pathInfo['dirname'];
     $ok = is_uploaded_file($this->_ArrayDoc['tmp_name']);
     if ($ok) {
         if (exif_imagetype($this->_ArrayDoc['tmp_name'])) {
             // Tratamiento de la imagen antes de subirla
             list($ancho, $alto) = getimagesize($this->_ArrayDoc['tmp_name']);
             if ($this->_ArrayDoc['maxWidth'] > 0 and $ancho > $this->_ArrayDoc['maxWidth']) {
                 $ancho = $this->_ArrayDoc['maxWidth'];
             }
             if ($this->_ArrayDoc['maxHeight'] > 0 and $alto > $this->_ArrayDoc['maxHeight']) {
                 $alto = $this->_ArrayDoc['maxHeight'];
             }
             $img = new Gd();
             $img->loadImage($this->_ArrayDoc['tmp_name']);
             //$img->crop($ancho, $alto,$this->_ArrayDoc['modoRecortar']);
             $img->crop($this->_ArrayDoc['maxWidth'], $this->_ArrayDoc['maxHeight'], $this->_ArrayDoc['modoRecortar']);
             $imagenRecortada = "tmp/" . md5($this->_ArrayDoc['tmp_name']);
             $ok = $img->save($imagenRecortada);
             unset($img);
             $archivo = new Archivo($imagenRecortada);
             $this->setSize($archivo->getSize());
             $this->setWidth($archivo->getImageWidth());
             $this->setHeight($archivo->getImageHeight());
             $this->setMimeType($archivo->getMimeType());
             unset($archivo);
             $archivoSubir = $imagenRecortada;
         } else {
             $archivo = new Archivo($this->_ArrayDoc['tmp_name']);
             $this->setSize($archivo->getSize());
             $this->setMimeType($archivo->getMimeType());
             unset($archivo);
             $archivoSubir = $this->_ArrayDoc['tmp_name'];
         }
         $ftp = new Ftp($_SESSION['project']['ftp']);
         if ($ftp) {
             //echo $carpetaDestino," ",$archivoSubir;
             $ok = $ftp->upLoad($carpetaDestino, $archivoSubir, $this->Name);
             $this->_errores = $ftp->getErrores();
             $ftp->close();
         } else {
             echo "error ftp";
             $this->_errores[] = "Fallo al conectar vía FTP";
         }
         unset($ftp);
         $ok = count($this->_errores) == 0;
         if (file_exists($imagenRecortada)) {
             @unlink($imagenRecortada);
         }
     }
     return $ok;
 }