I have a public function that downloads a JSON file. I would like it to redirect to the index (base_url
) after the download is complete. I tried using the ob_start
and ob_flush
PHP functions but that doesn't do it. Is this possible?
$this->load->helper('url');
$data['events'] = $this->events_model->get_events();
ob_start();
header("Content-Description: File Transfer");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename='EVENTS.json'");
echo json_encode($data);
ob_flush();
redirect(base_url());