public function actualizar($codigo, $tipo = 'foto') { $aux = FALSE; $path = getcwd(); if (!is_dir(realpath($path . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . "paginas" . DIRECTORY_SEPARATOR))) { mkdir($path . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . "paginas" . DIRECTORY_SEPARATOR, 0755); } $config['upload_path'] = realpath("{$path}/images/paginas/"); $config['allowed_types'] = 'gif|jpg|jpeg|png|PNG|JPG|JPEG|GIF'; $config['max_size'] = '0'; $config['max_width'] = '0'; $config['max_height'] = '0'; $this->load->library('upload', $config); $ruta = str_replace(MY_Controller::base(), realpath($path), $this->ruta($codigo)); if (file_exists($ruta)) { if (substr($ruta, -1) != '/') { if (unlink($ruta)) { $aux = TRUE; log_message('info', 'La imagen ha sido borrada con éxito'); } else { $aux = FALSE; log_message('error', 'La imagen no ha sido borrada'); } } } if ($this->upload->do_upload('archivo')) { log_message('info', 'La nueva imagen ha sido subida con éxito'); $foto = $this->upload->data(); $config['image_library'] = 'gd2'; //CARPETA EN LA QUE ESTÁ LA IMAGEN A REDIMENSIONAR $config['source_image'] = realpath($path . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . "paginas" . DIRECTORY_SEPARATOR . $foto['file_name']); $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['new_image'] = realpath($path . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . "paginas" . DIRECTORY_SEPARATOR); if ($tipo == 'foto') { $config['width'] = 220; $config['height'] = 220; } else { $config['width'] = 960; $config['height'] = 350; } $this->image_lib->initialize($config); if (!$this->image_lib->resize()) { log_message('error', "Error imagen:" . $this->image_lib->display_errors()); } $this->image_lib->clear(); unlink(realpath($path . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . "paginas" . DIRECTORY_SEPARATOR . $foto['file_name'])); $this->Codigo = $codigo; $this->Ruta = base_url() . 'images/paginas/' . $foto['raw_name'] . '_thumb' . $foto['file_ext']; $this->Nombre = $foto['raw_name']; $this->Extension = $foto['file_ext']; $this->Tamanyo = $foto['file_size']; if ($this->db->update('Imagen', $this, array('Codigo' => $codigo))) { $aux = TRUE; } else { log_message('error', "Error imagen: No se ha introducido en la BD"); } } else { log_message('error', "Error imagen:" . $this->upload->display_errors()); } return $aux; }