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 8675949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:04:25+00:00 2026-06-12T20:04:25+00:00

I am trying to create a import tool that would read the csv file

  • 0

I am trying to create a import tool that would read the csv file and allow me to map it to a the table columns and import it. I am trying to do this using code igniter.

Has anyone does this and have a library or is there a tool available in php and/or codeigniter. I wanted to check before I try to reinvent the wheel.

  • 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-12T20:04:26+00:00Added an answer on June 12, 2026 at 8:04 pm

    I did something similar a long time ago, I’m feeling generous so here is a code snippet! 🙂

    I have the user select the appropriate fields from a form on the front end, but you can always hard code this in if your CSV file never changes.

    Obviously you will want to modify to your needs (delimiters, field names, etc…) but this should get you started in the right direction.

    // get POST values
    $objPost = (object) $this->input->post('arr_of_fields');
    
    $fh_csv = fopen('YOUR CSV FILE');
    $fh_tmp = fopen('YOUR TEMP FILE');
    
    while( false !== ($line = fgets($fh_csv)) )
    
        $enclosed = ''; // or whatever your field is enclosed with
        $delimiter = ','; // or whatever your delimiter is
    
        $columns  = explode($enclosed.$delimiter.$enclosed, trim($line, $enclosed));
    
        // the $objPost->field_X signifies the index for that field [0,1,2,3,+++]
        $data = array(
           'field_1' => trim(@$columns[@$objPost->field_1], $enclosed),
           'field_2' => trim(@$columns[@$objPost->field_2], $enclosed),
           'field_3' => trim(@$columns[@$objPost->field_3], $enclosed),
           'field_4' => trim(@$columns[@$objPost->field_4], $enclosed),
        );
    
        // write line to temp csv file, tab delimited with new line
        $str = implode("\t", $data) . "\n";
    
        @fwrite($fh_tmp, $str); // write line to temp file
    }
    @fclose($fh_csv);
    @fclose($fh_tmp);
    
    // import from temp csv file into database
    $sql    = sprintf("LOAD DATA LOCAL INFILE '%s'
                INTO TABLE `%s`
                FIELDS TERMINATED BY '\\t'
                LINES TERMINATED BY '\\n'
                (field_1, field_2, field_3, field_4)",
                "TEMP FILE",
                "DATABASE TABLE NAME");
    
    $query  = $this->db->query( $sql );
    
    // delete temp file
    @unlink("TEMP FILE");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an import statement that's pluggable with other projects. This statement
I am trying to create a SSIS package that will import Excel data to
I'm trying to create script, that will import keywords from images to database. Keywords
I am trying to create java objects from xml file. I am using jaxb(unmarshalling)
I am trying to create a fixed width flat file import spec in SSIS.
I'm trying to create an import program from CSV. My code is csv =
I'm trying to create an XML output file to import into another program. The
I'm trying to create a data import mechanism for a database that requires high
I'm trying to create a MainConfig that imports another Config by using an @Bean
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can

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.