php - How to import multiple csv files to mysql using codeigniter? -


i working in project need upload multiple csv file's data single table in database. have written code uploading zip file contains csv files , extracting in temp folder. not able write code reads each csv files , insert data mysql. kindly guide me.

here controller code

public function upload() {     $spcode = $this->input->post("spcode");     $config['upload_path']  = './adsl/';     $config['allowed_types'] = 'zip';     $data['msg'] = '';     $this->load->library('upload', $config);      // if upload failed, display error     if (!$this->upload->do_upload()) {         $data['msg'] = $this->upload->display_errors();     }     $this->load->view('templates/header');     $this->load->view('upload_wholesale', $data);     $this->load->view('templates/footer');  }  public function fetchfilesfromdirectory() {     $dir = "./adsl/";     $filesarr = array_diff(scandir($dir), array('..', '.'));     if(!empty($filesarr)) {         $zip = new ziparchive;         foreach($filesarr $filename) {             $file = "./adsl/".$filename;             chmod($file,0777);             if ($zip->open($file) === true) {                 $zip->extractto('./wholesaleuploads/');                 $zip->close();                 $chunkfile = explode(".", $filename);                 $extracted_files = directory_map("./wholesaleuploads/".$chunkfile[0]);                 chmod($extracted_files,0777);                       if ($this->csvimport->get_array($extracted_files)) {                         $csv_array = $this->csvimport->get_array($extracted_files);                         //print_r($csv_array);                         if(!empty($csv_array)) {                              foreach ($csv_array $row) {                                 $insert_data = array(                                     'accountnumber'=>$row['accountnumber'],                                     'custid'=>$row['custid'],                                     'servicenumber'=>$row['servicenumber'],                                     'servicetype'=>$row['service type'],                                     'chargetype'=>$row['chargetype'],                                     'details'=>$row['details'],                                     'datefrom'=>$row['datefrom'],                                     'dateto'=>$row['dateto'],                                     'charge'=>$row['charge'],                                     'gst'=>$row['gst'],                                     'payment'=>$row['payment'],                                     'invoicenumber'=>$row['invoicenumber'],                                     'spcode'=>$spcode,                                 );                                  $this->upload_adsl->insert_csv($insert_data);                             }                         }                             $this->upload_adsl->addfiles($chunkfile[0].".csv");                             unlink($file); // remove resource directory.                             unlink($extracted_files); // remove upload directory.                             echo "file uploaded successfully.";                     }              }          }     } } 

}


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -