title: How can I save TXT Files from a HTML textarea, using PHP?
body: <p>I am trying to make a text file storage system for my website.</p>
  
  <p>Here is what I have so far.</p>
  
  <p>I have gotten some parts to work, but am getting many more errors after making a few changes I thought would help.</p>
  
  <p>I am trying to accomplish this task without changing pages or url.</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
      &lt;body&gt;
          &lt;?php
      if (isset($_POST)){
          //Save File
          $file = fopen($_POST['filename'] &amp; ".txt","r+");
          $text = $_POST["textdata"];
          file_put_contents($file, $text);
          fclose($file);
          //Open File
          $file = fopen($_POST['filename'] &amp; ".txt", "r") or exit("Unable to open file.");
          while(!feof($file)){
              echo fgets($file). "&lt;br /&gt;";
          }
          fclose($file);
      }
  
      echo '
      &lt;form name="savefile" method="post" action="' . $_SERVER['PHP_SELF'] . '"&gt;
          File Name: &lt;input type="text" name="filename" value=""&gt;&lt;br/&gt;
          &lt;textarea rows="20" cols="100" name="textdata"&gt;&lt;/textarea&gt;&lt;br/&gt;
          &lt;input type="submit" name="submit" value="Save Text to Server"&gt;
  &lt;/form&gt;
      &lt;br/&gt;&lt;hr style="width: 100%; height: 4px;"&gt;&lt;br/&gt;
      &lt;form name="openfile" method="post" action="' . $_SERVER['PHP_SELF'] . '"&gt;
          Open File: &lt;input type="text" name="filename" value=""&gt;
          &lt;input type="submit" name="submit" value="Submit File Request"&gt;
  &lt;/form&gt;';
      ?&gt;
      &lt;/body&gt;
  &lt;html&gt;
  </code></pre>
  
  <p>If the only way is to have it redirect to a php page, then send it back, that is fine, but I have no clue how to do that, (even though its probably A LOT simpler)</p>
  
  <p>Thanks for any help or advice you can provide me!</p>
  
  <p>-Jake</p>