Skip to content

Instantly share code, notes, and snippets.

@kirasiris
Last active February 14, 2018 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirasiris/48361a28a07d0045cd95e4a20c546c5a to your computer and use it in GitHub Desktop.
Save kirasiris/48361a28a07d0045cd95e4a20c546c5a to your computer and use it in GitHub Desktop.
<?php
/*
*
*Este metodo trabaja con la version 3.1.6 en adelante de CodeIgniter
*
*/
// Preferencias para subir imagenes
$config['upload_path'] = 'assets/img/posts/';
$config['allowed_types'] = 'gif|jpg|png';
$config['encrypt_name'] = TRUE;
$config['max_size'] = '2048';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
// Muy importante que pongas esto
$this->load->library('upload', $config);
$this->upload->initialize($config);
// El input para subir imagenes/archivos normalmente se llama "userfile". Si el input va con diferente nombre, replazalo aqui.
$file_name = 'post_image';
// Procesa el archivo subido. Asegurate de poner el nombre de la variable $file_name en donde debe.
if(!$this->upload->do_upload($file_name)){
$this->upload->display_errors();
$file_name = 'assets/img/noimage.jpg';
} else {
$post_image = $this->upload->data('file_name');
}
// Page Data
$data = array(
'slug' => $slug,
'title' => $this->input->post('title'),
// Aqui subes la imagen a la base de datos
'post_image' => $post_image,
'body' => $this->input->post('body'),
'order' => $this->input->post('order'),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment