Yet another Excel file upload mime type problem - El Forum - 01-20-2012
[eluser]raenk[/eluser]
I have searched and checked every (i think) excel related issue with the upload class and mime type check and still haven't found a solution.
When trying to upload an excel file the upload errors out stating the file type is not allowed, which of course is.
I checked the array at the mimes.php file, added some new to no avail. Then I print the $_[FILE] element holding the type uploaded and it had the audacity to print a type which IS included in the mimes.php file.
Can't fight that.
Any pointers ?
Thanks
Yet another Excel file upload mime type problem - El Forum - 01-20-2012
[eluser]InsiteFX[/eluser]
Here are some more mine types you can add.
Code: Mime type:
application/vnd.ms-excel [official],
application/msexcel,
application/x-msexcel,
application/x-ms-excel,
application/vnd.ms-excel,
application/x-excel,
application/x-dos_ms_excel,
application/xls
Yet another Excel file upload mime type problem - El Forum - 01-20-2012
[eluser]raenk[/eluser]
Thanks InsiteFX, but I got'em all. The fun comes when printing $_FILES['uerfile']['type'] and see it is detected as application/vnd.ms-excel which IS allowed.
Yet another Excel file upload mime type problem - El Forum - 01-23-2012
[eluser]raenk[/eluser]
Ok, I'll pass some more information for this case:
Controller method:
Code: function agregar_lista()
{
if($this->admin_model->get_permisos($this->session->userdata('id'), 'edicion_precios'))
{
$this->form_validation->set_rules('fecha', '"Fecha"', 'trim|required')
->set_rules('nombre', '"Nombre"', 'trim|required')
->set_rules('categoria', '"CategorÃa"', 'trim|callback__cat_vacia')
->set_rules('archivo', '"Achivo"', 'callback__checa_archivo')
->set_message('required', 'Esta información es necesaria.');
$data['sec_title'] = "Administrador Web";
if ($this->form_validation->run() == FALSE)
{
$data['categorias'] = $this->admin_model->get_registros('categorias_clientes');
$data['main_content'] = 'admin_agregar_lista_precios';
$data['error'] = '';
$this->load->view('admin_template', $data);
} else {
$this->load->library('upload');
$config['upload_path'] = './assets/adjuntos/precios/';
$config['allowed_types'] = 'pdf|xl|xls|xlsx';
$this->upload->initialize($config);
if($this->upload->do_upload('archivo'))
{
$archivo_data = $this->upload->data();
} else {
$data['error'] = $this->upload->display_errors('<p class="msg">', '</p>') . $_FILES['archivo']['type'];
}
$config['upload_path'] = './assets/adjuntos/precios/iconos/';
$config['allowed_types'] = 'jpg|jpeg|gif|png';
$config['max_size'] = '100';
$config['max_width'] = '100';
$config['max_height'] = '150';
$this->upload->initialize($config);
if(empty($data['error']) && !empty($_FILES['icono']['name']))
{
if($this->upload->do_upload('icono'))
{
$icono_data = $this->upload->data();
} else {
$data['error'] = $this->upload->display_errors('<p class="msg">', '</p>');
}
} else {
$icono_data['file_name'] = 'lista-sample.jpg';
}
if(empty($data['error']))
{
$data = array(
'nombre' => $this->input->post('nombre'),
'fecha' => $this->input->post('fecha'),
'archivo' => $archivo_data['file_name'],
'icono' => $icono_data['file_name'],
'cliente_cat' => $this->input->post('categoria'),
'usuario' => $this->session->userdata('id')
);
$this->admin_model->agregar_registro('listas_precios', $data);
$data['sec_title'] = "Administrador Web";
$data ['main_content'] = 'admin_lista_agregada';
$this->load->view('admin_template', $data);
} else {
$data['main_content'] = 'admin_agregar_lista_precios';
$this->load->view('admin_template', $data);
}
}
} else {
$this->restringido();
}
}
continue...
Yet another Excel file upload mime type problem - El Forum - 01-23-2012
[eluser]raenk[/eluser]
My mimes.php array
Code: $mimes = array( 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xls' => array('application/vnd.ms-excel', 'application/vnd.ms-excel [official]', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download'),
'hqx' => 'application/mac-binhex40',
'cpt' => 'application/mac-compactpro',
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
'bin' => 'application/macbinary',
'dms' => 'application/octet-stream',
'lha' => 'application/octet-stream',
'lzh' => 'application/octet-stream',
'exe' => array('application/octet-stream', 'application/x-msdownload'),
'class' => 'application/octet-stream',
'psd' => 'application/x-photoshop',
'so' => 'application/octet-stream',
'sea' => 'application/octet-stream',
'dll' => 'application/octet-stream',
'oda' => 'application/oda',
'pdf' => array('application/pdf', 'application/x-download'),
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
'smi' => 'application/smil',
'smil' => 'application/smil',
'mif' => 'application/vnd.mif',
'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'),
'wbxml' => 'application/wbxml',
'wmlc' => 'application/wmlc',
'dcr' => 'application/x-director',
'dir' => 'application/x-director',
'dxr' => 'application/x-director',
'dvi' => 'application/x-dvi',
'gtar' => 'application/x-gtar',
'gz' => 'application/x-gzip',
'php' => 'application/x-httpd-php',
'php4' => 'application/x-httpd-php',
'php3' => 'application/x-httpd-php',
'phtml' => 'application/x-httpd-php',
'phps' => 'application/x-httpd-php-source',
'js' => 'application/x-javascript',
'swf' => 'application/x-shockwave-flash',
'sit' => 'application/x-stuffit',
'tar' => 'application/x-tar',
'tgz' => array('application/x-tar', 'application/x-gzip-compressed'),
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'),
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mpga' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
'aif' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'ram' => 'audio/x-pn-realaudio',
'rm' => 'audio/x-pn-realaudio',
'rpm' => 'audio/x-pn-realaudio-plugin',
'ra' => 'audio/x-realaudio',
'rv' => 'video/vnd.rn-realvideo',
'wav' => 'audio/x-wav',
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'jpeg' => array('image/jpeg', 'image/pjpeg'),
'jpg' => array('image/jpeg', 'image/pjpeg'),
'jpe' => array('image/jpeg', 'image/pjpeg'),
'png' => array('image/png', 'image/x-png'),
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'css' => 'text/css',
'html' => 'text/html',
'htm' => 'text/html',
'shtml' => 'text/html',
'txt' => 'text/plain',
'text' => 'text/plain',
'log' => array('text/plain', 'text/x-log'),
'rtx' => 'text/richtext',
'rtf' => 'text/rtf',
'xml' => 'text/xml',
'xsl' => 'text/xml',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpe' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'avi' => 'video/x-msvideo',
'movie' => 'video/x-sgi-movie',
'doc' => 'application/msword',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'word' => array('application/msword', 'application/octet-stream'),
'xl' => 'application/excel',
'eml' => 'message/rfc822',
'json' => array('application/json', 'text/json')
);
Thanks
Yet another Excel file upload mime type problem - El Forum - 01-28-2012
[eluser]TheFuzzy0ne[/eluser]
I'm not sure what's going on there. Everything looks fine to me.
You can make a copy of ./system/libraries/Upload.php and copy it over into ./application/libraries, then you can edit/debug it. Once you've found the problem, you can just delete the file to go back to using the CodeIgniter version of the file.
Good luck!
Yet another Excel file upload mime type problem - El Forum - 01-28-2012
[eluser]Narf[/eluser]
If you're using CI 2.1 - try with this one:
https://raw.github.com/narfbg/CodeIgniter/320ddaa3d01c9d8ee6832fa25f9273e2588c63dd/system/libraries/Upload.php
Yet another Excel file upload mime type problem - El Forum - 01-30-2012
[eluser]hcker2000[/eluser]
That new upload library Narf linked to worked for me.
Yet another Excel file upload mime type problem - El Forum - 01-30-2012
[eluser]raenk[/eluser]
Not working for me. What's different in this library from the default one ?
Thanks
Yet another Excel file upload mime type problem - El Forum - 01-30-2012
[eluser]hcker2000[/eluser]
Just for the record I limited it to gif jpg and png files and it was failing on known valid jpg's. Thats what the new upload library solved for me.
|