Last active
February 14, 2018 21:08
-
-
Save kirasiris/48361a28a07d0045cd95e4a20c546c5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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