0

I want to upload csv file and xls file, my code has given below
`

        `$configUpload['upload_path'] = './user_status/';`
         $configUpload['allowed_types'] = 'XLS|text/comma-separated-values|application/csv|application/excel|application/vnd.ms-excel|application/vnd.msexcel|text/anytext|text/plain|text/csv|csv|application/vnd.ms-excel';
         $configUpload['max_size'] = '5000';
         $this->load->library('upload', $configUpload);
         $this->upload->do_upload('input field name')`;

my csv file is uploading very well but when I choose xls file then codeigniter show error that "The filetype you are attempting to upload is not allowed".

Result of print_r($_FILES) is

Array ( [user_status_csv] => Array ( [name] => VTRACK.XLS [type] => application/vnd.ms-excel [tmp_name] => C:\xampp\tmp\phpB2C4.tmp [error] => 0 [size] => 2627412 ) ) 
2
  • did you check using 'xls' in the allowed_types value ? ? Aug 15, 2012 at 7:43
  • yes but same error is showing. Aug 15, 2012 at 7:45

5 Answers 5

2

I had the same problem. and i solved by modifying the mime for xls

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

to

array('application/excel', 'application/vnd.ms-excel', 'application/octet-stream'),
1

You can also try XLSX

 $configUpload['allowed_types'] = '**XLSX|**XLS|text/comma-separated-values|application/csv|application/excel|application/vnd.ms-excel|application/vnd.msexcel|text/anytext|text/plain|text/csv|csv|application/vnd.ms-excel';

Also you can just give the file extensions as this

 $configUpload['allowed_types'] = 'xls|xlsx|csv';
1
1

You can try to use sollution from similair topic. Answer suggests that browser sends xls(x) as application/zip.

Please refer to this topic: Upload xls or xlsx files with codeigniter, mime-type error

Sollution:

I have added/replaced the following line to the mime types file (application/config/mimes.php):

'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/zip'),
0

You have to set the mime type in mimes.php configuration file. You can determine your file mime type using data() method in upload file calss

Please check the following :

http://isaber.info/blog/2013/01/23/codeigniter-upload-files-not-work/

0

The xls or xlsx,csv problem is with the mime type.

The solution is:

if ( $this->upload->do_upload('filename') ){
       $img = $this->upload->data();
       $ext = $img['file_ext'];                            
       $post['xlfile'] = time().$ext;
} else {
       var_dump($this->upload->data());
       exit();                            
       redirect('hr/hr/dashboard/');
}

If the excel file failed to upload, then in the else condition write

var_dump($this->upload->data()); So, The type of mime will be identified. Copy the output array by index name file_type.

'file_type' => string 'application/vnd.ms-office' (length=25)

Then open the mimes.php in application/config/ folder.

Search for the xls, xlsx and add the following mime type for the array.

Maximum it covers all the mime types.

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

This will work like charm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.