Next
Update
Prev
Import
Scan Record
Change History
Change History (XML)

You can import a CSV-formatted File by using the KoolGrid API, excelCSVImport() and any server-side script (such as ASP, PHP, etc). Click the Import button and enter the number of header rows and choose the CSV-formatted text file you want to import.

function excelCSVImport() {
  gridRoot.excelCSVImport(0, "http://www.koolchart.com/koolgrid/server/importCSV.php");
}

[importCSV.php]
<?php
/*
 * This PHP code is an example of how to process the CSV file uploaded using Apache Common Fileupload.
 * KoolGrid uploads the CSV file using the input file tag, and on the server side the CSV file is read and processed.
*/

  $path = $_SERVER['DOCUMENT_ROOT'] . "/koolgrid/upload/";
  $count = 0;
  $file_upload = false;
  $max_allowed_file_size = 100000000; //

  if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
    foreach($_FILES as $file) {
      $name = $path . $file['name'];
        if (is_uploaded_file($file['tmp_name'])) {
          if(!copy($file['tmp_name'], $name)) {
            $message[] = "Error while copying the uploaded file.";
          } else {
            $outStr = "fileName=" . urlencode($file['name']) . "&csvStr=";
            $size = filesize($file['tmp_name']) + strlen($outStr);
            header("Content-Type: text/html; charset=utf-8");
            header("Content-Length: $size");
							
            $myfile = fopen($file['tmp_name'], "r") or die("Unable to open file!");
            while (($data = fgetcsv($myfile, 1024, ",")) !== FALSE) {
              $num = count($data);
              for ($c=0; $c < $num; $c++) {
                if ($c == $num-1)
                  $outStr .= $data[$c] . "<br>";
                else
                  $outStr .= $data[$c] . ",";
              }
            }							
            fclose($myfile);
							
            echo $outStr;
          }
        }
    }
  }
?>

© 2017 KoolChart. All rights reserved.