Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7917757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:15:30+00:00 2026-06-03T15:15:30+00:00

I always got an invalid file type error in uploading csv file in codeigniter.

  • 0

I always got an invalid file type error in uploading csv file in codeigniter. I already googled for possible mime types for csv and still nothing works. so I bother echoing the echo $_FILES[‘userfile’][‘type’]; and I got this MIME type : ‘application/force-download’. Below is a snippet from the controller and a snippet from the view

Controller:

public function upload_file()
{

 $status = "";
 $msg = "";
 $file_element_name = 'userfile';

 if (empty($_POST['title']))
 {
  $status = "error";
  $msg = "Please enter a title";
 }

 if ($status != "error")
 {
  $config['upload_path'] = './uploads/csv_list/';
  $config['allowed_types'] = 'gif|jpg|png|doc|txt|.csv';
  $config['max_size']  = 1024 * 8;

  if (!$this->upload->do_upload($file_element_name))
  {
     $status = 'error';
     $msg = $this->upload->display_errors('', '');

  }
  else
  {

        $status = "success";
        $msg = "File successfully uploaded";

  }
  @unlink($_FILES[$file_element_name]);
  }
  echo json_encode(array('status' => $status, 'msg' => $msg));
}

View:

  <input type="text" name="title" id="title" value="a" style ="display:none"/>

<p>
  <input type="text" name="title" id="title" value="a" style ="display:none"/>  
  <label for="userfile">Upload CSV File</label>
  <input type="file" name="userfile" id="userfile" size="20" />
  <input type="submit" name="submit" id="submit" value ="Upload"/>
</p>

<script>
    $(function () {
        $('#upload_file').submit(function (e) {
            e.preventDefault();
            $.ajaxFileUpload({
                url: '../upload/upload_file/',
                secureuri: false,
                fileElementId: 'userfile',
                dataType: 'json',
                data: {
                    'title': $('#title').val()
                },
                success: function (data, status) {
                    if (data.status != 'error') {
                        $('#files').html('<p>Reloading files...</p>');
                        // refresh_files();
                        // $("#userfile").replaceWith("<input type=\"file\" id=\"userfile\" size =    \"20\" />");
                        $('#files').html('File Uploaded');
                        // $('#title').val('');
                    }
                    alert(data.msg);
                }
            });
            return false;
        });
    });
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T15:15:31+00:00Added an answer on June 3, 2026 at 3:15 pm

    The problem here is that different web browser gets different ideas on what type a file is. Since CodeIgniter’s upload class is dependent of file types, this can get messy.

    I followed several instruction to add more types to the fields in the config/ but neither did the trick.

    I ended up with allowing all types $config['allowed_types'] = '*' and validated like this instead:

    if (in_array(end(explode('.', $str_file_name)), array('php')))
        return FALSE;
    

    or in your case:

    $arr_validate = array('gif', 'jpg', 'png', 'doc', 'txt', 'csv');
    
    if ( ! in_array(end(explode('.', $str_file_name)), $arr_validate))
        return FALSE;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I always got this error guys on my site.Anybody got a solution. Stacktrace at
I always got failed to fetching of list failed error. This is my connection
a bit new to CI, googled and overflowed alot and still got no answer
i always got error: Code Sign error: A valid provisioning profile matching the application's
I got one main search field always visible at the site and a login
I can't find a way to get through this error. I've got this code
I got a simple XML file that I want to validate against an XSD.
I've got wcf web-service(basicHttpBinding). Our Delphi7 clients couldn't correct consume it. I've already flatten
I've got a data file of the form: Series_1 12-Dec-2011 12:00 32 Series_1 12-Dec-2011
This has always got me. I change the nameservers with the registrar and then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.