1

I have a Codeigniter project that can insert data into database through uploading an excel file and reading it with PHPExcel. It is working on my localhost however when I uploaded it in a LAMP server, It gives me an error The filetype you are attempting to upload is not allowed. How am I going to solve this?

EDIT In my project, I also have a file image uploading..

 public function uploadConfig(){
    $this->load->library('PHPExcel');  
    $this->load->library('PHPExcel/IOFactory');
    $config['upload_path'] = './csv_uploads/'; 
    $config['allowed_types'] = 'xlsx|csv|xls';
    $config['max_size'] = '10000'; 
    $config['overwrite'] = true;
    $config['encrypt_name'] = FALSE;
    $config['remove_spaces'] = TRUE;

    $this->load->library('upload', $config);
    $this->upload->initialize($config);

    if (!is_dir('csv_uploads'))
    {
        mkdir('./csv_uploads', 0777, true);
    }
    // gif|jpg|jpeg|png
}

This works on my localhost in XAMPP. However, when I uploaded it on my LAMP server, it didn't work.

d_unknown
  • 875
  • 3
  • 15
  • 41
  • plz add bit of upload function code – Linus Oct 30 '15 at 02:55
  • Possible duplicate of [Codeigniter : The filetype you are attempting to upload is not allowed. Yesterday it was fine](http://stackoverflow.com/questions/21868995/codeigniter-the-filetype-you-are-attempting-to-upload-is-not-allowed-yesterda) – MuntingInsekto Oct 30 '15 at 03:04
  • try checking allowed mime type `$config['allowed_types'] = 'xls'`; is there – Linus Oct 30 '15 at 03:05
  • @vnpnlz, it is working on my localhost. – d_unknown Oct 30 '15 at 03:10
  • can you add this lines `'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/zip'),` to `application/config/mimes.php` – MuntingInsekto Oct 30 '15 at 03:13
  • can you check result of `var_dump(print_r($_FILES));` put this in controller and tell – Linus Oct 30 '15 at 03:16
  • @vnpnlz, I do have something like that in mime.php.. the problem occured when I uploaded it in the server which is LAMP.. but in my localhost, it is working and I am using XAMPP.. – d_unknown Oct 30 '15 at 03:18
  • @AnmolRaghuvanshiVersion1.0, this is the result: **Array ( [files] => Array ( [name] => Book1.xlsx [type] => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet [tmp_name] => /tmp/phpIj8rmv [error] => 0 [size] => 10618 ) ) boolean true The filetype you are attempting to upload is not allowed.** – d_unknown Oct 30 '15 at 03:21
  • please check the php.ini file with below configuration with ; Whether to allow HTTP file uploads. `file_uploads = On` is on or not may be lamp problem – Linus Oct 30 '15 at 03:28
  • @AnmolRaghuvanshiVersion1.0, it is already **on**. And by the way, **.xls** file can be uploaded.. only the **.csv** and **.xlsx** can't be uploaded. – d_unknown Oct 30 '15 at 03:49
  • which version of codeigniter are you using and which OS? – Linus Oct 30 '15 at 03:52
  • @AnmolRaghuvanshiVersion1.0, I am using 2.1.3 and in my localhost, windows 8.1.. while on server, Turnkey lamp (linux) – d_unknown Oct 30 '15 at 03:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/93749/discussion-between-anmol-raghuvanshi-version-1-0-and-d-unknown). – Linus Oct 30 '15 at 04:02
  • Also, you are trying to upload file that is bigger than allowed (10000<10618). – Tpojka Oct 30 '15 at 10:06

6 Answers6

4

For The file type you are attempting to upload is not allowed this issue occur because of your file type is wrong or not fulfill.

Please apply below step to get your file type.

You can looking at system/libraries/Upload.php line 199:

$this->_file_mime_type($_FILES[$field]);

Update that line to:

 $this->_file_mime_type($_FILES[$field]); var_dump($this->file_type); die();

Now you can see your actual file type Like xlsx or csv or xls or ods

Now you can add your file type below code

$config['allowed_types'] = 'xlsx|csv|xls';

also add in config/mimes.php

HEMAL
  • 420
  • 3
  • 14
  • it only displaying **string 'application/vnd.ms-excel' (length=24)** – d_unknown Nov 02 '15 at 01:45
  • go to application/config/mimes.php and apply below changes 'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'), to array('application/excel', 'application/vnd.ms-excel', 'application/octet-stream'), – HEMAL Nov 02 '15 at 05:57
  • thank you for your help. I noticed that I should just add the string displayed to mimes.php that corresponds to the file extension to be uploaded.. – d_unknown Nov 02 '15 at 06:48
3

Codeigniter 3

add to your config/mimes.php types 'application/octet-stream'

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

then it will work

Vitor Novo
  • 31
  • 2
1

Go to config/mimes.php -> lines no 32 (xls) -> add 'application/vnd.ms-office' into existing array.

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

This work only for xls for any other type get the mime type and add into this array.

웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
Anup
  • 169
  • 8
0

In your code

$config['allowed_types'] = 'xlsx|csv|xls';

But in Ubuntu it save file types is ods format. So it will never let allow to upload. add that

$config['allowed_types'] = 'xlsx|csv|xls|ods';

And in config/mimes.php

add this

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

Provide Permeation to write in the folder

sudo chown apache:apache -R /var/www/html

and in php.ini

  1. Check file_upload is on
  2. and check max upload limit
  3. as well as check max execution time
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

If you are using liberOffice or Open Office, You will face this problem. add "application/octet-stream" type in 'xlsx' to your application/config/mimes.php

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

In Your Code Add Below Line

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

this is configuration setting.

Raman Kumar
  • 131
  • 8