-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.php
executable file
·107 lines (99 loc) · 2.95 KB
/
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
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
<?php
session_start();
$roll=$_SESSION['userroll'];
$action=0;
$targetfolder = "/var/www/html/iiitg_portal/";
$targetfolder = $targetfolder . basename( $_FILES['file']['name']) ;
if(move_uploaded_file($_FILES['file']['tmp_name'], $targetfolder))
$action=1;
require 'config.php';
$code_id=$_GET['Code_id'];
$dir="practice_solution/";
$count="ls ".$dir." | wc -l";
$sum=shell_exec($count);
$sum=intval($sum);
$date=date("Y-m-d");
$time=date("h:i:s");
$sum=$sum+1;
$filesol=$dir."SOL".$sum.".txt";
$permission="chmod -R 777 practice_solution/";
$submission=$sum;
shell_exec($permission);
$languageID=$_POST["language"];
switch($languageID)
{
case "C":
{
$filename_code="main.c";
$file_code=fopen($filename_code,"w+");
if($action==1)
{
fwrite($file_code,file_get_contents(basename( $_FILES['file']['name'])));
fclose($file_code);
}
else
{
$code=$_POST["code"];
fwrite($file_code,$code);
fclose($file_code);
}
include("compilers/c.php");
break;
}
case "Python":
{
$filename_code="main.py";
$file_code=fopen($filename_code,"w+");
if($action==1)
{
fwrite($file_code,file_get_contents(basename( $_FILES['file']['name'])));
fclose($file_code);
}
else
{
$code=$_POST["code"];
fwrite($file_code,$code);
fclose($file_code);
}
include("compilers/py.php");
break;
}
case "C++":
{
$filename_code="main.cpp";
$file_code=fopen($filename_code,"w+");
if($action==1)
{
fwrite($file_code,file_get_contents(basename( $_FILES['file']['name'])));
fclose($file_code);
}
else
{
$code=$_POST["code"];
fwrite($file_code,$code);
fclose($file_code);
}
include("compilers/cpp.php");
break;
}
case "Java":
{
if($action==1)
{
$filename_code=basename($_FILES['file']['name']);
$name=basename($filename_code,".java");
$out="java"." ".$name;
}
else
{
$filename_code="main.java";
$file_code=fopen($filename_code,"w+");
$code=$_POST["code"];
fwrite($file_code,$code);
fclose($file_code);
}
include("compilers/java.php");
break;
}
}
?>