slice.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. //include_once("your_auth_script_here");
  3. //variable checking functions
  4. function mv($val){
  5. if (isset($_GET[$val]) && $_GET[$val] != ""){
  6. return $_GET[$val];
  7. }else{
  8. return "";
  9. }
  10. }
  11. //Setup the required directories
  12. $filename = "";
  13. if (mv("inputfile") != ""){
  14. $filename = mv("inputfile");
  15. if (file_exists("input/" . $filename)){
  16. //Ok to proceed.
  17. }else{
  18. die("ERROR. The given filename does not exists in the input/ folder.");
  19. }
  20. }else{
  21. die("ERROR. Undefined inputfile filename. (Usage: index.php?inputfile={filenamehere}");
  22. }
  23. $profileDir = "templates/";
  24. $slicingProfile = "default.txt";
  25. if (mv("profile") != ""){
  26. $slicingProfile = mv("profile");
  27. }
  28. if (!file_exists($profileDir . $slicingProfile)){
  29. die("ERROR. Slicing config template (template.txt) not exists.");
  30. }else{
  31. $template = file_get_contents($profileDir . $slicingProfile);
  32. $outfilename = time() . ".gcode";
  33. $outFile = "output/" . $outfilename;
  34. $cmd = str_replace("{inputfilename}","input/" . $filename,$template);
  35. $cmd = str_replace("{outputfilename}",$outFile,$cmd);
  36. //cmd ready to be sliced
  37. $returnedValue = shell_exec("sudo CuraEngine " . $cmd);
  38. //echo the newly created filename for the gcode conversion
  39. echo $outfilename;
  40. //Removing the converted stl file to save spaces
  41. unlink("input/" . $filename);
  42. }
  43. ?>