2

If I upload a csv file, there is no problem on localhost and everything works fine, but when I upload my app on live server and upload a csv file then this error thrown: The filetype you are attempting to upload is not allowed. I am confused as to why this happens. Please help me to solve this.

For my localhost environment, I am using XAMPP and CodeIgniter.

I only want to allow csv file uploads.

AstroCB
  • 12,337
  • 20
  • 57
  • 73
Bruice Danial
  • 25
  • 1
  • 3
  • Would be use full if you could edit your post and place your controller for upload and view. http://stackoverflow.com/questions/21399056/csv-file-upload-not-working-with-codeigniter and http://stackoverflow.com/questions/27201741/upload-pdf-csv-and-other-file-type-in-codeigniter –  Mar 20 '15 at 13:58

2 Answers2

4

check 2 things:

First: in your upload controller: make sure to set the correct allowed types

$config['allowed_types'] = 'csv';
$this->load->library('upload', $config);

Second: update the array $mimes in your config/mimes.php:

'csv'   =>  array('application/vnd.ms-excel', 
           'text/anytext', 
           'text/plain', 
           'text/x-comma-separated-values', 
           'text/comma-separated-values', 
           'application/octet-stream', 
           'application/vnd.ms-excel', 
           'application/x-csv', 
           'text/x-csv', 
           'text/csv', 
           'application/csv', 
           'application/excel', 
           'application/vnd.msexcel')

UPDATE:

you could use print_r($_FILES) in your upload controller to check for the mime-type missing. this would output something like:

[userfile] => Array
    (
        [name] => teste1.csv
        [type] => application/vnd.ms-excel
        [tmp_name] => C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\binaries\tmp\php8BFD.tmp
        [error] => 0
        [size] => 7880
    )
Vickel
  • 7,879
  • 6
  • 35
  • 56
  • This worked for me, printing out $_FILES, thank you. For those who are wondering .msg files needs the MIME type of: `application/octet-stream` – evade Jul 01 '15 at 14:42
  • Hi, I was trying to upload xls file but able to do so, though I have updated the file type in config/mimes.php still can not figure out why the error is persistent "The filetype you are attempting to upload is not allowed." – Nazmul Hasan Sheum Nov 16 '22 at 13:20
  • @NazmulHasanSheum: this post is about csv mime type; for excel see: https://stackoverflow.com/questions/974079/setting-mime-type-for-excel-document. Btw. did you print_r($_FILES)? – Vickel Nov 16 '22 at 16:56
1

Add ‘text/plain’ to the CSV array in config/mimes.php to $mimes arrays, that is

'csv'   =>  array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'),
Aditya Lepcha
  • 194
  • 1
  • 1
  • 11