i run a query on a database. i create a txt file with the query results. now i want that txt file to be sent to the browser, so the person that runs the report can save it to their local drive.
im trying it via headers, and here is what i have so far:
Code: Select all
<?php
$output_file = fopen("tmp_report.txt", "wb");
fwrite($output_file, $output_txt);
fclose($output_file);
$download_size = filesize("tmp_report.txt");
header("Content-type: application/x-download");
header("Content-Disposition: attachment; filename=tmp_report.txt;");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
@readfile("tmp_report.txt");
exit;
?>