PHP - export function output directly to a download file
Hello,
in PHP Nette, I would like to export $ rows records from the function below directly to a file, without displaying the results. Just for the browser to start downloading the result and not display it. The function is, for example, as follows:
Hi,
use the header as follows:
Description - The loop goes through $rows and saves them as an export.txt file.
in PHP Nette, I would like to export $ rows records from the function below directly to a file, without displaying the results. Just for the browser to start downloading the result and not display it. The function is, for example, as follows:
public function actionExport($d_id)
{
$rows = $this->modelExport->getExport($d_id);
}
REPLY
Hi,
use the header as follows:
public function actionExport($d_id)
{
$rows = $this->modelExport->getExport($d_id);
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename='export.txt');
foreach ($rows as $r) {
echo "$r\n";
}
exit();
}
Description - The loop goes through $rows and saves them as an export.txt file.