如何在codeigniter中读取CSV文件的内容

Sar*_*tra 1 php csv codeigniter

我已经使用 multipart-form 将 CSV 上传到 codeigniter,这是 HTML 代码:

<label for="enterCSV">Enter CSV            
<input  type="file"  name="enterCSV" accept=".csv">
</label>
Run Code Online (Sandbox Code Playgroud)

这是控制器上的php代码:

  $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
            }
Run Code Online (Sandbox Code Playgroud)

我只想使用我的 php 读取上传的 csv 文件的内容并相应地对其进行操作。

小智 5

你可以试试这个:

$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


}
Run Code Online (Sandbox Code Playgroud)