It's pretty well documented that adding a header is the way to make a link downloadable, but I must be doing something wrong. I write the file, and then produce some HTML linking to it, but the file will not download, only appear in the browser.
<?
//unique id
$unique = time();
$test_name = "HTML_for_test_" . $unique . ".txt";
//I should put the file name I want the header attached to here (?)
header("Content-disposition: attachment;filename=$test_name");
$test_handler = fopen($test_name, 'w') or die("no");
fwrite($test_handler, $test);
fclose($test_handler);
?>
<a href="<?=$test_name">Download File</a>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…