0
How to Force Download a Text File?
I have this code but it is not downloaded, when I click on the link its contents 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>
What is your doubt?
– Math
Colleague, the file will be created wherever your PHP is. To download just click on save as there at the end. What is the question?
– Diego
Do I need to download the generated file into a folder on the pc when clicking (Click here to download) ? As is it only opens in the browser...
– checktech
The server has no knowledge of client folders, so the file goes to the default download folder set by the browser.
– rray
I have already noticed in the download default folder and it is not listed...
– checktech
The text is displayed on a page when you click on the link that? the correct one would be to download??
– rray