-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathajax.php
executable file
·62 lines (51 loc) · 1.67 KB
/
ajax.php
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
include "prim.php";
$primsAlgorithm = new PrimsAlgorithm();
if(isset($_POST['node_no']) && isset($_FILES['file'])){
$fileData = $_FILES['file'];
$node_no = $_POST['node_no'];
$graph = processInputData($node_no, $fileData);
$response = $primsAlgorithm->Prim($graph, $node_no, $stepProcess = 1);
if(!empty(array_filter($response))){
$response['status'] = 1;
} else {
$response['status'] = 0;
}
echo json_encode($response);
return ;
} else {
die("Not catching Ajax Call");
}
?>
<?php
function processInputData($node_no, $files) {
$uploaddir = __DIR__ . '/uploads';
$new_graph = array();
$errors= array();
$file_name = $files['name'];
$file_size =$files['size'];
$file_tmp =$files['tmp_name'];
$file_type=$files['type'];
if (move_uploaded_file($files['tmp_name'], "$uploaddir/$file_name")) {
ini_set("memory_limit",-1);
$input_file = "$uploaddir/$file_name";
$myfile = fopen($input_file, "r") or die("Unable to open file!");
$i = 0;
while(! feof($myfile))
{
$lines = fgets($myfile); // one line in each time
// this is because at the end of the line it's generating empty array
if ($lines === false) {
break;
}
$splitedArray = preg_split('#\s+#', $lines, null, PREG_SPLIT_NO_EMPTY);
$new_graph[$i] = $splitedArray;
$i++;
}
}else{
echo "file is not uploaded.";
}
fclose($myfile);
return $new_graph;
}
?>