I am writing a php page to download a file from server to users. Here is my code:
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);
I am facing the problem: when user click the download button, the server send the file to users. While users downloading the file, users click download button again, the request does not execute now (all other request could not execute). When users download the first file completely, the second file is start.
Usually this happens when you are using a session. Check out this post. If you do not need session – simply turn it of for a download page. Or if you need it there – take all values you need at the beginning of a script and close session immediately. That will allow another script to be executed.