简体   繁体   English

使用请求下载cakephp2后,如何重定向到另一个页面

[英]How can I redirect to a another page after using request download cakephp2

I want to asking one question how to redirect to another page after using $this->response->download; 我想问一个问题如何在使用$this->response->download;后重定向到另一个页面$this->response->download; by cakephp 2 .I already use : by cakephp 2.我已经使用:

$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 这是另一种方式吗?谢谢

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 (eg 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. 因此,将用户重定向到您希望他们结束的位置,然后提供下载。

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';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在CakePHP2上允许访问“页面” - How to allow access to a 'Page' on CakePHP2 按下提交按钮后,如何重定向到另一个页面? - How can I redirect to another page after submit button pressed? 如何从CakePHP中的ajax调用重定向父页面? - How can I redirect the parent page from an ajax call in CakePHP? 如何使用当前站点cookie登录到另一个站点,然后重定向到另一个页面并发出CURL请求? - How can I use current site cookies to login to another site and then redirect to another page and make a CURL request? Cakephp2:如何在cakephp2的链接中显示内容的数量 - Cakephp2: How to display number of contents within the link in the cakephp2 如何调整Paginator CakePHP2? - How to adjust to the Paginator CakePHP2? 如何下载文件然后重定向到PHP中的另一页? - How to download a file then redirect to another page in php? 验证信用卡验证后如何重定向到另一个页面? - How can I redirect to another page after verifying the credit card validation? php成功响应后,如何将用户重定向到ajax中的另一个页面 - how can i redirect users to another page in ajax after success response from php 我如何将用户重定向到用户页面并将管理员重定向到 cakephp 中的管理页面 - how can i redirect user to the user page and admin to the admin page in cakephp
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM