Forums

csv import action

teldrive 11 Mar, 2015
Hi , I used a example of Bob and doesn't cost me too much to adapt it, i missed it in DataManagement Action, I suggest you to include it
<?php
$row    = 0;
$file   = "jobs/" . $form->data['file1'];
 // get the name of file to import
$indice = array();
if (($gestor = fopen($file, "r")) !== false) {

  //----------------------------start import data
  while (($datos  = fgetcsv($gestor, 1000, ";")) !== false) {

    //we know in first row are always  the name of fields, we just want some of them (i gues could be  be fields-name a variable )
    if ($fila == 0) {
      $indice[]        = array_search('field1', $datos);

      // ................................
      $indice[]        = array_search('fieldx', $datos);
      echo $indice;
    }
    else {
      $a = $row - 1;

      // we process import now all the data
      $form->data['model'][$a]['field1']   = $datos[$indice[0]];

      // .................................
      $form->data['model'][$a]['fieldx']   = $datos[$indice[x]];
    }
    $row++;
  }
  $form->data['numregs'] = $row;
}
fclose($gestor);
?>
This topic is locked and no more replies can be posted.