Forcing download of txt file via PHP is including HTML
<p>Basically, the user will be exporting some data to a txt file. That txt file will then download automatically. The download is working fine and is showing the data I want it to. However, the HTML of the actual page is getting appended onto the end of it?</p>

<pre><code>$fh = fopen($filename, 'w');
fwrite($fh, $data); 
fclose($fh);

header('Content-disposition: attachment; filename='.$filename);
header('Content-type:  text/plain');
readfile($filename);
</code></pre>
