title: Wordpress Plugin that creates a .json file
body: <p>I am currently creating a Wordpress plugin that reads the SQL tables of that site and converts them to JSON format.</p>
  
  <p>I am also able to output that data in the said plugin's admin page. However, I am unable to enter that data into a .json file and have it downloaded. Basically this file won't run:</p>
  
  <pre><code>file_put_contents("$db.json", json_encode($import));
  </code></pre>
  
  <p>I was given a few hints:</p>
  
  <p>Add the following headers: </p>
  
  <pre><code>header("Content-Description: File Transfer"); 
  header("Content-Type: text/plain"); 
  header("Content-Disposition: attachment; filename=\"test.json\""); 
  </code></pre>
  
  <p>However, I cannot do that as it gives me the error that I cannot add additional headers after the initialization process ends (HTML is loaded onto the page). </p>
  
  <p>Is anyone able to give me some direction on this issue?</p>
  
  <p>High overview is: </p>
  
  <ol>
  <li>Plugin is downloaded. </li>
  <li>Users provide the username/password and database name in order to gain access to the SQL tables (via a form).</li>
  <li>Submit form which runs a script once the form is submitted with that data a script uses it to spit out a JSON file. </li>
  </ol>
  
  <p>Should you need additional information, please ask.</p>
  
  <p>Thank you,</p>