How do I force a text file to be downloaded?
I have this code but it is not downloaded, when I click the link your content is displayed by the browser.
<?php
include "conecte.php";
$querymail = mysql_query("select cod,name from usuarios");
fopen("listar.txt", "w+");
while($data = mysql_fetch_array($querymail)) {
$log = str_pad($data[0], 30, " ", STR_PAD_RIGHT);
$log2 = str_pad($data[1], 30, "0", STR_PAD_RIGHT);
if (!$savelog = fopen('listar.txt', "a")){
exit;
}
if (!fwrite($savelog, $log . $log2. "\r\n")){
exit; fclose($savelog);
}
}
?>
<a href="listar.txt">Clique aqui para baixar</a>