Reputation: 205
I have a button that runs the below code. The csv file writes fine, but for some reason it is not downloading. Nothing happens, no errors. I have used the force download before and it has worked fine.
Any ideas?
$csvContent = $this->dbutil->csv_from_result($query);
$date = date('U');
$filename = date('Y-m-d-Gis', $date);
if (!write_file("./reports/$filename.csv", $csvContent)) {
echo 'Unable to write the file';
} else {
echo 'File written!';
$data = file_get_contents("reports/$filename.csv");
force_download($filename, $data);
}
Upvotes: 2
Views: 2190
Reputation: 12295
You should try $data = file_get_contents("./reports/$filename.csv");
instead ;)
Upvotes: 1