-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
107 lines (94 loc) · 2.58 KB
/
upload.php
File metadata and controls
107 lines (94 loc) · 2.58 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$ERROR = 0;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
//Allow only .mat file format
if($imageFileType != "mat" ) {
$MESSAGE = "Sorry, only MAT files are allowed.";
$ERROR = 1;
$uploadOk = 0;
?>
<script type='text/javascript'>
var mes = <?php echo json_encode($MESSAGE); ?>;
alert(mes);
window.location.replace("index.html");
</script>
<?php
exit();
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
$MESSAGE = "Sorry, your file is too large.";
$ERROR = 1;
$uploadOk = 0;
?>
<script type='text/javascript'>
var mes = <?php echo json_encode($MESSAGE); ?>;
alert(mes);
window.location.replace("index.html");
</script>
<?php
exit();
}
//Upload the file
$value = $_POST["inputThr"];
if ((0 <= $value) && ($value <= 1)){
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
$command = 'scripts/generateJavascript.py -t '.$_POST["inputThr"]. ' -i "uploads/'.basename($_FILES["fileToUpload"]["name"]).'"';
$MESSAGE = shell_exec($command);
if ($MESSAGE <> ""){
$ERROR = 1;
}
} else {
$MESSAGE = "Sorry, there was an error uploading your file.";
$ERROR = 1;
}
}else {
$MESSAGE = "Sorry, the entered threshold must be between 0 and 1.";
$ERROR = 1;
}
if($ERROR == 1){
?>
<script type='text/javascript'>
var mes = <?php echo json_encode($MESSAGE); ?>;
alert(mes);
window.location.replace("index.html");
</script>
<?php
}
else{
?>
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<link rel="stylesheet" type="text/css" href="visual.css">
<!-- Bootstrap core CSS -->
<link href="bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="signin.css" rel="stylesheet">
</head>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="scripts/visualization.js"></script>
<h1><?php echo $output ?></h1>
<p id="chart">
</p>
<div class="row">
<div class="col-md-1 text-center">
<button class="btn btn-lg btn-primary btn-block" onclick="goBack()">Go Back</button>
</div>
</div>
<script>
function goBack() {
window.history.back();
}
</script>
<script>
var jsonName = <?php echo '"uploads/'. substr(basename($_FILES["fileToUpload"]["name"]),0,-4). '.json"'; ?>;
var threshold = <?php echo $_POST["inputThr"]; ?>;
visualization(jsonName);
</script>
</body>
<?php } ?>