Alphy
Alphy

Reputation: 145

CodeIgniter: Excel file upload Error

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';

Upvotes: 0

Views: 6212

Answers (7)

Abdulla Nilam
Abdulla Nilam

Reputation: 38584

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';

Upvotes: 0

Vladimir Kattsov
Vladimir Kattsov

Reputation: 11

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'.

Upvotes: 1

Randika Vishman
Randika Vishman

Reputation: 8124

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!!!

Upvotes: 0

Raja Ram T
Raja Ram T

Reputation: 864

'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

Upvotes: 0

Carlos Avalos
Carlos Avalos

Reputation: 247

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.

Upvotes: 0

Carlos Avalos
Carlos Avalos

Reputation: 247

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'),

Upvotes: 0

Denmark
Denmark

Reputation: 538

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')

Upvotes: 0

Related Questions