/** * Moves the image file to a new location. * * @access protected * @param Symfony\Component\HttpFoundation\File\UploadedFile $file * @return string|null - en caso de fallo al guardar el archivo. */ protected function saveImage(UploadedFile $file) { $directory = $this->makeDirectory(self::IMAGEN_DIRECTORY_PATH); if ($file = $this->moveWithRename($directory, $file)) { // recupero la ruta relativa del archivo: $file = path_segment($file->getRealPath(), self::IMAGEN_DIRECTORY_PATH); } else { $file = null; } return $file; }
/** * MUTATOR * * Normalize the previsualizacion file path. * * @access public * @param string */ public function setPrevisualizacionAttribute($value) { $path = path_segment($value, 'media/'); $this->attributes['previsualizacion'] = normalize_path($path); }
/** * Moves the image file to a new location. * * @access protected * @param Symfony\Component\HttpFoundation\File\UploadedFile $file * @param integer $id * @return string|null - en caso de fallo al guardar el archivo. */ protected function saveImage(UploadedFile $file, $id) { $uniq = uniqid($file->getClientOriginalName(), true); $hash = sha1($uniq); $name = sprintf("%s.%s", $hash, $file->guessExtension()); $directory = $this->makeDirectory(self::LOGOTIPO_DIRECTORY_PATH . $id); if ($file = $file->move($directory, $name)) { // recupero la ruta relativa del archivo: $file = path_segment($file->getRealPath(), self::LOGOTIPO_DIRECTORY_PATH); $size = imgsize($file); // cambia el tamaño del logotipo proporcionalmente a 160px: if ($size->getWidth() > 160 or $size->getHeight() > 160) { $file = imgscale($file, 160); } $file = path_segment($file, self::LOGOTIPO_DIRECTORY_PATH); } else { $file = null; } return $file; }