3

I want to asking one question how to redirect to another page after using $this->response->download; by cakephp 2 .I already use :

$this->response->download($new_file_name);
print($output);
$this->Flash->success(__('The file has been successfully export.'));
return $this->redirect(array('action' => 'index'));

but it not working well. Is it any another way ?Thanks

art
  • 313
  • 2
  • 5
  • 19

2 Answers2

2

This can't be done, it's a limitation in how browser requests work. You can find more information in this answer.

The common thing (e.g. in popular download sites) is the reverse: first you go to the "after" page and then the download starts.

So, redirect the user to where you want them to end up, and then serve the download.

Community
  • 1
  • 1
Nick Zinger
  • 1,174
  • 1
  • 12
  • 28
0

Try this,but not sure that will worked.

$download='no';
$this->response->download($new_file_name);
print($output);
$download='yes';
if($download=='yes')
{
return $this->redirect(array('action' => 'index'));
}
else 
echo 'sorry did not downloaded';
Riajul Islam
  • 1,425
  • 15
  • 19