Trying to write to a file and force download with php
<p>Im using the following code to present a file for download. The file saves on the server correctly with the data, and prompts for download, but the downloaded file is empty. The new file is in the same directory as this script.</p>

<pre><code>&lt;?php

if(strlen($_POST['name'])&lt;1){
echo "error: you must enter a filename&lt;br&gt;&lt;a href=data.php&gt;back&lt;/a&gt;";
exit();
}

$name = $_POST['name'];
$data = file_get_contents("temp.php");

$fh = fopen("$name", 'w') or die("can't open file");
fwrite($fh, $data);
fclose($fh);

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Length: ". filesize("$name").";");
header("Content-Disposition: attachment; filename=$name");
header("Content-Type: application/octet-stream; "); 
header("Content-Transfer-Encoding: binary");

?&gt;
</code></pre>
