/** * 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; }
public function file($info) { $info['options']['extra'] = '<p class="form_inner_form"><input type="checkbox" name="' . htmlspecialchars($name) . '_crop" id="' . htmlspecialchars($name) . '_crop" checked="checked" value="yes" /><label for="' . htmlspecialchars($name) . '_crop">Crop After Upload</label></p>'; $out = $this->basic_input($info); // Located in libraries folder $gd = new Gd(); // Check if there is already and image / file in place and display it to the user if ($gd->load_file('./files/uploads/large/' . $info['value'])) { $out .= '<span class="current">Current Image: <a href="' . WEB_ROOT . 'files/uploads/large/' . htmlspecialchars($info['value']) . '" rel="facebox">' . htmlspecialchars($info['value']) . '</a></span>'; } else { $out .= '<span class="current">Current File: <a href="' . WEB_ROOT . 'files/uploads/original/' . htmlspecialchars($info['value']) . '" rel="external">' . htmlspecialchars($info['value']) . '</a></span>'; } return $out; }
/** * Generate thumbnail * * @throws Exception * @return string Path to new file */ public function generate() { $dir = $this->path . '/.thumb/' . $this->width . 'x' . $this->height; if (!is_dir($dir) && !mkdir($dir, 0755, true)) { throw new Exception("Thumbnail image can't be save. Parent directory is not writable"); } // Thumbnail already exists // then remove it and regenerate if (file_exists($dir . '/' . $this->file)) { unlink($dir . '/' . $this->file); } if (class_exists('\\Imagick')) { $image = new \Imagick($this->path . '/' . $this->file); } elseif (function_exists('gd_info')) { $image = new Gd($this->path . '/' . $this->file); } else { // return original file return $this->path . '/' . $this->file; } $image->cropThumbnailImage($this->width, $this->height); $image->writeimage($dir . '/' . $this->file); return $dir . '/' . $this->file; }