I have a small script that reads data from a database, massages it and saves it as a .txt file. At the end, the user is redirected to this file. Now, how to achieve this, when the user is redirected to .txt, the file download window will appear?
<?php
$MOD_NEWS_SAVETXT_getnews = mysql_query("SELECT * FROM NEWS WHERE NEWSid = '{$_GET['id']}'") or die(mysql_error());
while ($MOD_NEWS_SAVETXT_NEWSRESULT = mysql_fetch_array($MOD_NEWS_SAVETXT_getnews)) {
$MOD_NEWS_SAVETXT_FILE_name = $MOD_NEWS_SAVETXT_NEWSRESULT['NEWStitle'] . ".txt";
echo $MOD_NEWS_SAVETXT_FILE_name;
$MOD_NEWS_SAVETXT_FILE_handle = fopen($MOD_NEWS_SAVETXT_FILE_name, 'w') or die("Ne morem brati/ustvariti datoteke!");
fwrite($MOD_NEWS_SAVETXT_FILE_handle, $MOD_NEWS_SAVETXT_NEWSRESULT['NEWStext']);
fclose($MOD_NEWS_SAVETXT_FILE_handle);
header("Location: ./" . $MOD_NEWS_SAVETXT_FILE_name ."");
}
?>
source
share