Ver Mensaje Individual
  #3 (permalink)  
Antiguo 13/02/2016, 10:59
allamosash
 
Fecha de Ingreso: marzo-2015
Mensajes: 45
Antigüedad: 9 años, 5 meses
Puntos: 0
Respuesta: upload de imagenes

Utiliza este codigo a mi me funciona perfecto y se crea el thumb .
Código PHP:
Ver original
  1. Funcion:
  2.     function do_upload() {
  3.         //PASAMOS VALORES DEL PDF
  4.         if ($_POST["action"] == "upload")  
  5.         {
  6.             // obtenemos los datos del archivo  
  7.             $tamano = $_FILES["archivo"]['size'];
  8.             $tipo = $_FILES["archivo"]['type'];
  9.             $archivo = $_FILES["archivo"]['name'];
  10.              
  11.             if ($archivo != "")  
  12.             {
  13.                 // guardamos el archivo a la carpeta ficheros
  14.                 $destino =  "assets/pdf/".$archivo;
  15.                 if (copy($_FILES['archivo']['tmp_name'],$destino)){}  
  16.             }  
  17.         }  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.        
  24.         //SI EL FORMULARIO PASA LA VALIDACIÓN HACEMOS TODO LO QUE SIGUE
  25.  
  26.         $config['upload_path'] = './assets/img/slides/';
  27.         $config['allowed_types'] = 'gif|jpg|png';
  28.         $config['max_size'] = '2000000000';
  29.         $config['max_width'] = '20000000024';
  30.         $config['max_height'] = '200000008';
  31.  
  32.         $this->load->library('upload', $config);
  33.         //SI LA IMAGEN FALLA AL SUBIR MOSTRAMOS EL ERROR EN LA VISTA UPLOAD_VIEW
  34.         if (!$this->upload->do_upload()) {
  35.             $error = array('error' => $this->upload->display_errors());
  36.             $this->load->view('upload_view', $error);
  37.         } else {
  38.         //EN OTRO CASO SUBIMOS LA IMAGEN, CREAMOS LA MINIATURA Y HACEMOS
  39.         //ENVÍAMOS LOS DATOS AL MODELO PARA HACER LA INSERCIÓN
  40.             $file_info = $this->upload->data();
  41.             //USAMOS LA FUNCIÓN create_thumbnail Y LE PASAMOS EL NOMBRE DE LA IMAGEN,
  42.             //ASÍ YA TENEMOS LA IMAGEN REDIMENSIONADA
  43.             $this->_create_thumbnail($file_info['file_name']);
  44.             $data = array('upload_data' => $this->upload->data());
  45.             $titulo = $this->input->post('titulo');
  46.             $imagen = $file_info['file_name'];
  47.             $subir = $this->M_galeria->subir($titulo,$imagen,$archivo);      
  48.             $data['titulo'] = $titulo;
  49.             $data['imagen'] = $imagen;
  50.             Redirect('Home');
  51.         }
  52.  
  53.     }


Código PHP:
Ver original
  1. <?=form_open_multipart(base_url()."galeria/Galeria/do_upload")?>
  2.     <label>Descripcion:</label><input type="text" name="titulo" /><br><br><br>
  3.     <input name="action" type="hidden" value="upload" />
  4.     <label>AGREGAR PDF</label>
  5.     <input name="archivo" type="file"  id="archivo" size="35" /> <br><br><br>
  6.     <label>Agregar Imagen</label><input type="file" name="userfile" /><br><br><br>
  7.     <input type="submit" value="Subir imágenes" />
  8. <?=form_close()?>