-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess.php
More file actions
executable file
·59 lines (51 loc) · 1.66 KB
/
Copy pathprocess.php
File metadata and controls
executable file
·59 lines (51 loc) · 1.66 KB
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
<?php require("header.php"); ?>
<?php
include "prim.php";
$primsAlgorithm = new PrimsAlgorithm();
if(isset($_POST['btn-upload']))
{
if(!empty($_FILES['input_file']['name'])){
$fileData = $_FILES['input_file'];
$node_no = $_POST['node_no'];
$new_graph = processInputData($node_no, $fileData);
$primsAlgorithm->Prim($new_graph, $node_no);
} else {
die("you did not select any input file");
}
} 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{
die("Error. File is not being read. Please try again!");
}
fclose($myfile);
return $new_graph;
}
?>
<?php require("footer.php"); ?>