1

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());
jleft
  • 3,457
  • 1
  • 23
  • 35
septemberbrain
  • 998
  • 9
  • 25

1 Answers1

0

function redirect() does not work after 'echo';

before redirect you can't echo anything in browser

please comment this row:

//echo json_encode($data);