如何在Codeigniter中读取CSV文件的内容
问题描述:
我已使用多部分格式将CSV上传到codeigniter,这是HTML代码:
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>
这是控制器上的php代码:
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
}
我只想读取文件的内容
答
您可以尝试以下操作:
$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
}