文件下载期间网站的浏览器暂停


Browser halt for the site during file download

我有一小块代码可以帮助下载文件。但是该网站在文件下载期间没有打开/工作,但是当我在其他浏览器上打开该网站时,它就可以工作了。我不知道文件下载期间浏览器发生了什么。以下是我用来下载zip文件的标头:

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");                        
header("Content-Description: File Transfer");
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename='"".$zipname."'"");
header("Content-Transfer-Encoding: binary");
//header("Content-Length: ".filesize($directory_location . '/' . $zipname));
ob_end_flush();

readfile($directory_location . '/' . $zipname);
ob_end_clean();

即使我不知道如何调试它,所以我从我的代码中得到了弱点。

因此,

既然您正在使用会话:

"打开"会话会在下载脚本运行时阻止其他脚本访问该会话。

session_write_close在将文件内容流式传输到客户端之前可以解决此问题。只需在检查完需要签入会话的任何内容后,以及在脚本的耗时部分开始之前调用它 - 这将释放会话上的锁,并且在下载脚本运行时调用的其他脚本可以再次访问会话。