Bring up Save As dialog within PHP
<p>I have a file, <strong>index2.php</strong> that has been written to by a form.</p>

<p>The whole content of this file, I have stored within a variable <code>$final_code</code> using an output buffer.</p>

<p>I now wish to add a "Download" button to the end of the page, that brings up a Save As dialog, allowing the user to save this file's source code (i.e. the variable) as a .txt - But I'm stumped.</p>

<p><strong>index2.php:</strong></p>

<pre><code>&lt;?php

// Start buffering the output
ob_start();

?&gt;

&lt;!-- INDEX2.PHP HTML ELEMENTS HERE --&gt;

&lt;?php
// Store the contents of the buffer
$final_code = ob_get_contents();

// Print the contents of the buffer
ob_end_flush();
?&gt;

&lt;form action="savefile.php" method="post"&gt;

Happy? Save this to file: &lt;input type="submit" name="savefile" value="Save" /&gt;

&lt;/form&gt;
</code></pre>

<p>I'm not sure if this needs to be worked in to this file or <strong>savefile.php</strong>, so the latter is currently blank.</p>
