PHP下载脚本在下载完成之前无法导航到其他页面
我在一个基于视频的网站上工作,我必须提供下载视频的链接 我使用了下面的代码,它工作得很好PHP下载脚本在下载完成之前无法导航到其他页面,php,cakephp,Php,Cakephp,我在一个基于视频的网站上工作,我必须提供下载视频的链接 我使用了下面的代码,它工作得很好 if (file_exists($FileDownload)) { $Basename = pathinfo($FileDownload, PATHINFO_BASENAME); $mime = 'application/force-download'; header('Pragma: public'); // required heade
if (file_exists($FileDownload)) {
$Basename = pathinfo($FileDownload, PATHINFO_BASENAME);
$mime = 'application/force-download';
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: ' . $mime);
header('Content-Disposition: attachment; filename="' . basename($Basename) . '"');
header('Content-Transfer-Encoding: binary');
header('Connection: close');
readfile("$FileDownload"); // push it out
exit();
}
$this->render(false);
它正在强制下载文件,它写在我的控制器操作上,我将视图渲染为false
问题是,当我点击下载并开始下载文件时,在下载完成之前,我无法导航到其他页面
谢谢 经过许多努力,我终于知道了答案 CakePhp响应文件是我问题的解决方案 更新代码
$FileDownload = base64_decode($FileDownload);
// Retrieve the file ready for download
$Basename = pathinfo($FileDownload, PATHINFO_BASENAME);
// Run any pre-download logic here.
// Send file as response
$this->response->file(
$FileDownload, array(
'download' => true,
'name' => $Basename
)
);
return $this->response;
你为什么希望能够做到这一点听起来像。此外,控制器不应回显数据!关于如何发送文件,请参考与CakePHP版本相匹配的食谱。您好,感谢您的快速回复,我的视频大小以MB(200)为单位,因此下载需要时间。所以,我无法在我的网站上做任何事情,如果我点击其他链接访问它继续加载不导航到其他页面,直到下载完成。