PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 4, 2022

[FIXED] unable to upload an excel file in codeigniter

 February 04, 2022     codeigniter, file-upload, lamp, phpexcel     No comments   

Issue

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.


Solution

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



Answered By - HEMAL
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing