-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathajax_csvfile.php
More file actions
38 lines (38 loc) · 846 Bytes
/
ajax_csvfile.php
File metadata and controls
38 lines (38 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?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!'
);
}
echo json_encode($return);