0

I am trying to upload excel file in CodeIgniter as i have specified below but it says invalid file. Is there a hidden issue with CodeIgniter or with my filetype specification?

$config['allowed_types'] = 'xls|xlsx';
Hasib Tarafder
  • 5,773
  • 3
  • 30
  • 44
Alphy
  • 145
  • 2
  • 5
  • 14

7 Answers7

1

I use this in my mime.php:

'xls'   =>  array('application/excel', 'application/vnd.ms-excel', 'application/vnd.ms-office', 'application/octet-stream', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/x-zip', 'application/vnd.ms-excel', 'application/msword'),
'xlsx'  =>  array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/x-zip', 'application/vnd.ms-excel', 'application/msword'),

Don't forget about 'application/vnd.ms-office'.

0

add this to your mimes.php also check your excel extention name

or you can use also

$config['allowed_types'] = '*';

'xlsx'  =>  array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip')
Denmark
  • 538
  • 2
  • 8
  • 26
0

I Found this solution

'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/x-zip', 'application/vnd.ms-excel', 'application/msword'),

'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/octet-stream'),

Carlos Avalos
  • 247
  • 4
  • 8
0

Other solution by joni jones Uploading in Codeigniter - The filetype you are attempting to upload is not allowed

If you don't want to change system files. Just try this:

Open system/libraries/Upload.php (method do_upload() line 205) and do this:

var_dump($this->file_type);
exit();

Try to upload some file. Add file type, which you see in var_dump() to application/config/mimes.php. Little example: you have problem with .docx. Try to add:

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

to application/config/mimes.php.

Community
  • 1
  • 1
Carlos Avalos
  • 247
  • 4
  • 8
0
'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/octet-stream'),

'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/x-zip', 'application/vnd.ms-excel', 'application/msword'),
'xls' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/x-zip', 'application/vnd.ms-excel', 'applica
    tion/msword'),

repalce with your previous mime type of xls and xlsx put the above code it can be work

xls two add not a problem

'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/octet-stream'), working in to the my local but not working this live sit(Production site)

'xls' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/x-zip', 'application/vnd.ms-excel', 'applica
        tion/msword'),

it is working on the live production site

i am placing two xls it both places working

David
  • 15,894
  • 22
  • 55
  • 66
Raja Ram T
  • 854
  • 8
  • 8
0

I got the same problems with CodeIgniter File Upploads and my version of CodeIgniter is currently 2.2.0 You can find an answer looking at my following answer!!!

Good Luck!!!

Community
  • 1
  • 1
Randika Vishman
  • 7,983
  • 3
  • 57
  • 80
0

In config/mimes.php

add this

'xlsx'  =>  array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'),
'xls'   =>  array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),
'ods'   =>  array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip')

and in your configuration

$config['allowed_types'] = 'xlsx|xls|ods';
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85