index.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <html>
  2. <head>
  3. <link href="css/jquery-linedtextarea.css" rel="stylesheet">
  4. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  5. <script src="js/jquery-linedtextarea.js"></script>
  6. </head>
  7. <body>
  8. <?php
  9. error_reporting(E_ALL & ~E_NOTICE);
  10. $path = realpath(dirname("."));
  11. if (isset($_FILES['srcfile']) && $_FILES['srcfile']['error'] === UPLOAD_ERR_OK) {
  12. $folder = $_FILES['srcfile']['tmp_name'] ;
  13. $file = $_FILES['srcfile']['name'];
  14. echo "folder: $folder<br/>";
  15. echo "filename: $file<br/>";
  16. if (isset($file)) {
  17. $source = file_get_contents($folder);
  18. $source = str_replace("\r", "", $source);
  19. $source = str_replace("\n", "\\n", $source);
  20. unlink ($file);
  21. }
  22. }
  23. $example = $_POST["examples"];
  24. if (isset($example)) {
  25. $files = glob($path."/examples/*.tps");
  26. foreach($files as $filename){
  27. if(is_file($filename)){
  28. $basename = basename($filename);
  29. if ($basename == $example) {
  30. $source = file_get_contents($filename);
  31. $source = str_replace("\r", "", $source);
  32. $source = str_replace("\n", "\\n", $source);
  33. $file = $basename;
  34. }
  35. }
  36. }
  37. }
  38. ?>
  39. <form method="post" enctype="multipart/form-data">
  40. <input type="file" name="srcfile"/>
  41. <button type="submit">load</button>
  42. </form>
  43. <form method="post">
  44. <label for="examples">Examples:</label>
  45. <select id="examples" name="examples" size="1">
  46. <?php
  47. $files = glob($path."/examples/*.tps");
  48. foreach($files as $filename){
  49. if(is_file($filename)){
  50. $basename = basename($filename);
  51. echo "<option value=\"$basename\">$basename</option>\r\n";
  52. }
  53. }
  54. ?>
  55. </select>
  56. <button type="submit">load</button>
  57. </form>
  58. <form method="post" action="ass.php" target="_blank">
  59. Name: <input id="name" name="name">
  60. <textarea class="lined" rows="20" cols="60" name="source"></textarea>
  61. <button type="submit">Assemble</button>
  62. </form>
  63. <script>
  64. $(document).ready(function(){
  65. $(".lined").linedtextarea();
  66. <?php
  67. if (isset($source)) {
  68. echo "\$(\".lined\").val(\"$source\");\r\n";
  69. }
  70. if (isset($file)) {
  71. echo "\$(\"#name\").val(\"$file\");\r\n";
  72. }
  73. ?>
  74. });
  75. </script>
  76. </body>
  77. </html>