textinput.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <html>
  2. <head>
  3. <!-- Inserting CodeMirror text editor -->
  4. <!-- Credit for the idea goes to Aditya Rajan -->
  5. <link rel="stylesheet" href="assets/codemirror.css">
  6. <script src="assets/codemirror.js"></script>
  7. <script src="assets/matchbrackets.js"></script>
  8. <script src="assets/clike.js"></script>
  9. <style>.CodeMirror {border: 1px solid #ccc; width:500px; }</style>
  10. </head>
  11. <body>
  12. <?php
  13. $saving = $_REQUEST['saving'];
  14. if ($saving == 1)
  15. {
  16. $data = $_POST['data'];
  17. $unique = rand(1, 10000);
  18. $file = "text".$unique.".txt";
  19. $fp = fopen($file, "w") or die("<p>Couldn't open $file for writing!</p>");
  20. fwrite($fp, $data) or die("<p>Couldn't write values to file!</p>");
  21. fclose($fp);
  22. echo "<p>Saved to $file successfully! You may now use $file as a text input for your program.</p>";
  23. }
  24. /* Code for taking text input. Similar to the first part of output.php */
  25. ?>
  26. <p>
  27. <form name="form1" method="post" action="?saving=1">
  28. Write your text here:
  29. <br>
  30. <!-- Text box to take text input for program -->
  31. <textarea id="textinput" name="data" cols="50" rows="10">
  32. This is the file you can use to provide input to your program and later on open it inside your program to process the input.
  33. </textarea>
  34. <br>
  35. <!-- Submit button goes here -->
  36. <input type="submit" value="Save">
  37. <br>
  38. <br>
  39. <!-- Link to close text input -->
  40. <a href="output.php">Click here to close text input</a>
  41. </form>
  42. </p>
  43. <script>
  44. var editor = CodeMirror.fromTextArea(document.getElementById("textinput"), {
  45. lineNumbers: true,
  46. matchBrackets: true,
  47. closeBrackets: true,
  48. lineWrapping: true,
  49. tabMode: "indent",
  50. indentUnit: 4,
  51. mode: "text"
  52. });
  53. </script>
  54. </body>
  55. </html>