title: Writing string to file and force download in PHP
body: <p>I'm looking into methods of how to create a file from a string, this could be plain text would save as .txt and php as .php etc but I was hoping to get some insight into it</p>
  
  <p>**I found this code</p>
  
  <pre><code>$file = 'people.txt';
  // Open the file to get existing content
  $current = file_get_contents($file);
  // Append a new person to the file
  $current .= "John Smith\n";
  // Write the contents back to the file
  file_put_contents($file, $current);
  </code></pre>
  
  <p>But would I need to have people.txt saved on my server? </p>
  
  <p><strong>The force download part</strong></p>
  
  <pre><code>header("Content-Disposition: attachment; filename=\"" . basename($File) . "\"");
  header("Content-Type: application/force-download");
  header("Content-Length: " . filesize($File));
  header("Connection: close");
  </code></pre>
  
  <p>Where would I need to house the above, I'm assuming the code is right to force download my ready made file?</p>