-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.php
More file actions
48 lines (45 loc) · 1.38 KB
/
Copy pathserver.php
File metadata and controls
48 lines (45 loc) · 1.38 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
<?php
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'compile':
compile();
break;
case 'download':
download();
break;
case 'upload':
upload();
break;
}
}
function compile() {
$code = $_POST['code'];
$request_id = uniqid();
$code = preg_replace_callback(
"/((hist|plot|boxplot)\(.*?\))/",
function($matches) {
$image_id = uniqid();
$result = "print('<img src=";
$result .= '"';
$result .= "./dumps/graphics/{$image_id}.png";
$result .= '">';
$result .= "')\n";
$result .= 'png(filename="';
$result .= "./dumps/graphics/{$image_id}.png";
$result .= '", width=500, height=500)';
$result .= "\n";
$result .= $matches[0];
$result .= "\ngraphics.off()\n";
return $result;
},
$code);
$output = array();
file_put_contents("./dumps/code/{$request_id}.r", $code);
exec("Rscript ./dumps/code/{$request_id}.r", $output);
$response = array("code" => stripslashes(implode($output)));
echo json_encode($response);
}
function upload() {
echo "I'm uploading";
}
?>