如何在Codeigniter中读取CSV文件的内容 [英] How to read content of CSV file in codeigniter
本文介绍了如何在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
}
这篇关于如何在Codeigniter中读取CSV文件的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文