2012-04-09 17 views
6

Estaba buscando mucho y encontré muchas preguntas sobre este problema, desafortunadamente ninguna de las respuestas me ayudó.CodeIgniter "No está permitido el tipo de archivo que está intentando cargar".

Estoy tratando de subir una imagen PNG, y yo estoy recibiendo el siguiente error:

The filetype you are attempting to upload is not allowed.

Estaba siguiendo esta guía CI para construir mi código: http://codeigniter.com/user_guide/libraries/file_uploading.html

Esto es lo que conseguido:

vista de archivo:

[..] 
    <?= form_open_multipart() ?> 
    <input type="file" name="userfile" size="20" /> 
    <br /><br /> 
    <input type="submit" value="upload" /> 
    <?= form_close() ?> 
[..] 

Mi controlador:

$config['upload_path'] = './uploads/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size']  = '100'; 
    $config['max_width']  = '1024'; 
    $config['max_height'] = '768'; 


     $this->load->library('upload', $config); 

     $xx = array('upload_data' => $this->upload->data()); 
     $mimetype= $xx['upload_data']['file_type']; 

     var_dump('Mime: ' . $mimetype); 
     var_dump($_FILES); 

     if (!$this->upload->do_upload()) 
     { 
      Notice::add($this->upload->display_errors(), 'error'); 
     } 
     else 
     { 
      $data['upload_data'] = $this->upload->data(); 
     } 

Como puedes ver, estoy tratando de var_dump el tipo de mime y el resultado está vacío.

Cuando hago var_dump($_FILES) Parece que todo está bien:

array(1) { ["userfile"]=> array(5) { ["name"]=> string(14) "imageofm.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(18) "/var/tmp/php5cDAZJ" ["error"]=> int(0) ["size"]=> int(358) } } 

Además, tengo 'png' => array('image/png', 'image/x-png'), línea, en mi config/mimes.php.

Sin embargo, ocurre para todas las imágenes (aún no se han probado otras extensiones).

Agradecería cualquier intento de ayuda.

Respuesta

1

Reemplazando el sistema codeigniter 2.1.0/libraries/upload.php con la versión 2.1.2 la biblioteca upload.php resuelve el problema. Espero que esto ayude

0

otra solución es permitir extension=php_fileinfo.dll en php.ini

7

sólo editar el archivo mimes.php en application/config/mimes.php y reemplazar la línea para el csv por éste:

'csv' => array('application/vnd.ms-excel', 'text/anytext', 'text/plain', 'text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel') 
+0

10 Ahí va, no es mi tipo de archivo (mp3), sino que me ayude resuelve mi problema –

1
$this->load->library('upload'); 

$this->upload->set_allowed_types('*'); 


class MY_Upload extends CI_Upload { 

    function is_allowed_filetype() { 

     if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types)) 
     { 
      $this->set_error('upload_no_file_types'); 
      return FALSE; 
     } 

     if (in_array("*", $this->allowed_types)) 
     { 
      return TRUE; 
     } 

     $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe'); 

     foreach ($this->allowed_types as $val) 
     { 
      $mime = $this->mimes_types(strtolower($val)); 

      // Images get some additional checks 
      if (in_array($val, $image_types)) 
      { 
       if (getimagesize($this->file_temp) === FALSE) 
       { 
        return FALSE; 
       } 
      } 

      if (is_array($mime)) 
      { 
       if (in_array($this->file_type, $mime, TRUE)) 
       { 
        return TRUE; 
       } 
      } 
      else 
      { 
       if ($mime == $this->file_type) 
       { 
        return TRUE; 
       } 
      } 
     } 

     return FALSE; 

    } 

} 
0

Puedo añadir esta línea en mime.php en la línea 34 y pptx ahora está cargando. probarlo en servidor real

'pptx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'),

4

Add 'text/plain' a la matriz CSV en config/mimes.php a $ mimos matrices

+0

Gracias - esto resolvió mi problema. Mi problema estaba relacionado directamente con los archivos CSV, con el mismo mensaje de error. –

Cuestiones relacionadas