简体   繁体   中英

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

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

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

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

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 .

'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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM