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

Thursday, March 24, 2022

[FIXED] How to read content of CSV file in codeigniter

 March 24, 2022     codeigniter, csv, php     No comments   

Issue

I have uploaded a CSV to codeigniter using a multipart-form, this is the HTML code:

<label for="enterCSV">Enter CSV            
<input  type="file"  name="enterCSV" accept=".csv">
</label>

and this is the php code on the controller:

  $csv = $_FILES['enterCSV']['name'];

            $file = fopen($csv, r); //open file
            while (!feof($file)){ //read till the end of the file
                $content = fgetcsv($file); //get content of the file
            }

I just want to read the content of the uploaded csv file using my php and manipulate it accordingly.


Solution

you can try this:

$csv = $_FILES['file']['tmp_name'];

$handle = fopen($csv,"r");
while (($row = fgetcsv($handle, 10000, ",")) != FALSE) //get row vales
{
    print_r($row); //rows in array

   //here you can manipulate the values by accessing the array


}


Answered By - Madhu
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • 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