1
0

output.php 898 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <html>
  2. <body>
  3. <?php
  4. $saving = $_REQUEST['saving'];
  5. if ($saving == 1){
  6. $data = $_POST['data'];
  7. $args = $_POST['args'];
  8. $stdin= $_POST['stdin'];
  9. $unique = rand(1, 10000);
  10. $file = "prog".$unique.".c";
  11. $srcpath = "./".$file;
  12. $executable = "./"."prog".$unique;
  13. $fp = fopen($file, "w") or die("<p>Couldn't open $file for writing!</p>");
  14. fwrite($fp, $data) or die("<p>Couldn't write values to file!</p>");
  15. fclose($fp);
  16. echo "<p>Saved to $file successfully!</p>";
  17. echo"<p>
  18. Compiling the program $file<br>
  19. Error list:<br>";
  20. $output1 = shell_exec("g++ $srcpath -o $executable 2>&1");
  21. echo "$output1";
  22. echo "</p>";
  23. echo "<p>Running the program:<br>";
  24. $output2 = shell_exec("echo $stdin | $executable $args");
  25. echo "$output2";
  26. echo "<br>
  27. </p>";
  28. shell_exec("rm -rf $srcpath $executable");
  29. }
  30. else {
  31. echo "<p>Enter your code in the left frame and hit run to display the output.</p>";
  32. }
  33. ?>
  34. </body>
  35. </html>