<?php /** * Created by PhpStorm. * User: a6y * Date: 21.08.15 * Time: 17:15 */ /** * Store csv file data in tmp table */ require_once 'src/autoload.php'; $return = array('Type' => 'Error', 'Mess' => 'Неизвестная ошибка'); if (($handle = fopen($_FILES["csvfile"]["tmp_name"], "r")) !== FALSE) { $result = new \Parser\Result(); $result->init(); $row = 0; while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) { $row++; // Skip csv header if ($row == 1) { continue; } if (!empty($data[0])) { $result->addLink($row, $data[0]); } } $return = array('Type' => 'OK', 'DATA' => $row - 1); } else { $return = array('Type' => 'Error', 'Mess' => 'Could not open csv!'); }
<?php /** * Created by PhpStorm. * User: a6y * Date: 26.08.15 * Time: 18:39 */ require_once 'src/autoload.php'; $result = new \Parser\Result(); $header = $result->getResultHeader(); $data = $result->getResultData(); if (isset($_GET['clear'])) { $result->clearResultData(); header("Location: " . basename(__FILE__)); } // Make csv file if (isset($_GET['download'])) { // output headers so that the file is downloaded rather than displayed header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=data.csv'); // create a file pointer connected to the output stream $output = fopen('php://output', 'w'); // output the column headings $heading = array(); foreach ($header as $column) { $heading[] = $column["name"]; } fputcsv($output, $heading); // loop over the rows, outputting them foreach ($data as $line) {