writeCode.php 748 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. include_once '../auth.php';
  3. include_once 'checkCodePathValid.php';
  4. if (isset($_POST['filename']) && isset($_POST['content'])){
  5. $filename = $_POST['filename'];
  6. $content = $_POST['content'];
  7. if (!file_exists($filename)){
  8. //Create a tmp file for realpath check
  9. file_put_contents($filename,"");
  10. }
  11. if (checkIfFilepathAllowed($filename)){
  12. file_put_contents($filename,$content);
  13. }else{
  14. //If you do not get the permission to write to this file, remove the tmp folder for realpath check
  15. if (file_exists($filename)){
  16. unlink($filename);
  17. }
  18. die("ERROR. No permission to write to this file. " . $filename . " was given.");
  19. }
  20. echo "DONE";
  21. exit(0);
  22. }else{
  23. die("ERROR. filepath or content undefined.");
  24. }
  25. ?>