Php 无法下载多个文件
我正在编写一个php页面,将文件从服务器下载给用户。这是我的密码:Php 无法下载多个文件,php,html,download,Php,Html,Download,我正在编写一个php页面,将文件从服务器下载给用户。这是我的密码: clearstatcache(); //Output stream to client header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false);
clearstatcache();
//Output stream to client
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=\"" . $zipName . "\"; filename*=utf-8''" . rawurlencode($zipName) . ";");
header("Content-Transfer-Encoding: binary");
header("Accept-Ranges: bytes");
header("Content-Length: " . (filesize($downloadFile)));
$fp = fopen($downloadFile, "rb");
ob_clean();
while (!feof($fp) && ( connection_status() == 0 ) && !connection_aborted()) {
print( fread($fp, 1024 * 1024));
flush();
ob_flush();
}
fclose($fp);
我面临的问题是:当用户单击下载按钮时,服务器将文件发送给用户。当用户下载文件时,用户再次单击下载按钮,请求现在不会执行(所有其他请求都无法执行)。当用户完全下载第一个文件时,第二个文件将启动 通常在使用会话时会发生这种情况。看看这个。如果您不需要会话,只需打开它的下载页面。或者,如果需要,在脚本开始时获取所需的所有值,并立即关闭会话。这将允许执行另一个脚本 顺便说一句,除非您知道如何处理范围请求,否则不要发送
接受范围:字节。我也不知道为什么每次都使用ob\u flush()
;我会在循环之前使用ob\u end\u clean()
。@杰克:非常感谢。我现在不使用会话。非常感谢您的链接。它解决了我的问题。