-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.php
28 lines (22 loc) · 899 Bytes
/
compile.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
<?php
require_once 'autoload.php';
require_once 'mono.php';
$received_code = isset($_POST['code']) ? $_POST['code'] : '';
$response = [];
if(strlen($received_code) > 0) {
// store file
$filename = RandomSequence(15, preg_replace('/(\.)|(:)/', '', $_SERVER['REMOTE_ADDR']) . uniqid());
$filepath = $code_storage_path . $filename;
$filepath_cs = $filepath . '.cs';
$filepath_exe = $filepath . '.exe';
file_put_contents($filepath_cs, $received_code);
// compile
$compiler_result = \mono\compile($filepath_cs, $cmd['compiler'], $compiler_tools_path);
$response['compiler'] = $compiler_result;
if ($compiler_result['exit_code'] == 0) {
$runtime_result = \mono\execute($filepath_exe, $cmd['runtime'], $compiler_tools_path);
$response['runtime'] = $runtime_result;
}
}
header('Content-Type: application/json');
echo json_encode($response);