如何在包含html标签的codeigniter中将csv文件导入MYSQL

时间:2015-06-18 10:44:12

标签: php mysql codeigniter csv

我想使用codeigniter将csv导入mysql。

这是我的源代码。

我有一个来自客户端的非标准化事件日记CSV,我试图加载到MySQL表中,以便我可以重构成一个理智的格式。

我创建了一个名为' CSVImport'对于CSV文件的每一列都有一个字段

lucene-core

请帮助我找到更好的解决方案。

上传csv后发现以下错误:

  

文件502 Bad Gateway

1 个答案:

答案 0 :(得分:0)

Once your file is uploaded then u should to fetch a row from uploaded using fgetcsv function of php
My Working Solution:

$p_Filepath ="your file path"
$file = fopen($p_Filepath, 'r');       
    $data = array();
    $i=0;

    while (! feof($file)) {
      $data[$i] = (fgetcsv($file));
      $i++;
    }

    $data1 = array();
    for($j=1;$j<count($data);$j++){
      $data1[$j] = array (
                  "date"          =>  $data[$j][0],
                  "time"          =>  $data[$j][1],
                  "type"          =>  $data[$j][2],
                  "source"        =>  $data[$j][3],
                  "contactName"   =>  $data[$j][4],
                  "phone"         =>  $data[$j][5],                        
                  "email"         =>  $data[$j][6],                        
                  "address"       =>  $data[$j][7],
                  "city"          =>  $data[$j][8],
                  "state"         =>  $data[$j][9],
                  "zip"           =>  $data[$j][10],
                  "language"      =>  $data[$j][11],
                  "practiceArea"  =>  $data[$j][12],
                  "practiceCategory"=>  $data[$j][13],
                  "actionable"    =>  $data[$j][14],
                  "billable"      =>  $data[$j][15],
                  "destNum"       =>  $data[$j][16],
                  "callDuration"  =>  $data[$j][17],
                  "pageUrl"       =>  $data[$j][18],
                  "emailRec"      =>  $data[$j][19]
                  );
      $this->db->insert("contactReport",$data1[$j]);      
    }