tags:

views:

29

answers:

1

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.

<?php

if(strlen($_POST['name'])<1){
echo "error: you must enter a filename<br><a href=data.php>back</a>";
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");

?>
+3  A: 

You never actually send the file to the user. Add this after the headers:

readfile($name);
reko_t
thanks! works great
Patrick