Skip to content Skip to sidebar Skip to footer

Cancel Long Running Download

I have a web application with a PHP server side language on NGINX. Via JS, a user is able to download a file which is constructed dynamically by PHP from a database that is very sl

Solution 1:

So I still have not been able to figure out a way with JavaScript to cancel an already initiated download that appears in the download manager of a browser. But, using session_write_close after session_start will allow these concurrency issues to be avoided, and therefore, multiple PHP scripts to be ran simultaneuosly (i.e. the download can still occur while a user is navigating the page in a different window)

header("Content-Disposition: attachment; filename=\"" . $filename . ".txt\"");
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Set-Cookie: fileDownload=" . $filename . "; path=/");   

session_write_close();
while (Stream::MORE_DATA == $client->receive($data)) {
   print $data;
   flush();
}

Post a Comment for "Cancel Long Running Download"