Hello,
I made a script for downloading files.
Let's say, if you want to download a file with .exe extension, a script will be requested, script.php:
$file = 'full/path/to/file.exe";
function dwfile($file)
{
if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT']))
{
// IE Bug in download name workaround
ini_set( 'zlib.output_compression','Off' );
}
header ('Content-type: ' . mime_content_type($file));
header ('Content-Disposition: attachment; filename="'.basename($file).'"');
header ('Expires: '.gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y"))).' GMT');
header ('Accept-Ranges: bytes');
header ('Cache-control: no-cache, must-revalidate');
header ('Pragma: private');
$size = filesize($file);
if(isset($_SERVER['HTTP_RANGE']))
{
list($a, $range)=explode("=",$_SERVER['HTTP_RANGE']);
//if yes, download missing part
str_replace($range, "-", $range);
$size2=$size-1;
$new_length=$size2-$range;
header("HTTP/1.1 206 Partial Content");
header("Content-Length: $new_length");
header("Content-Range: bytes $range$size2/$size");
}
else
{
$size2=$size-1;
header("Content-Range: bytes 0-$size2/$size");
header("Content-Length: ".$size);
}
if ($file = fopen($file, 'rb'))
{
while(!feof($file) and (connection_status()==0))
{
print(fread($file, 1024*8));
flush();
}
$status = (connection_status()==0);
fclose($file);
}
return($status);
}
dwfile($file);
I have the following problem:
the file it's starting to download, but if I want to use the browser window to navigate away from that page, I can't. Until the file is not downloaded, the browser window it's stucked.
I tried this on 3 different environments:
W2k3 - Apache/2.0.55 (Win32) PHP/5.0.5
Win2000Server - Apache/2.0.54 (Win32) mod_ssl/2.0.54 OpenSSL/0.9.7g PHP/5.0.4
Linux Fedora - Apache/2.0.52, PHP 4.3.10
It's the same problem.
Also, I tested it on Linux Environment, Apache 1.3.31, PHP 4.3.8, and here it's working!
So, I suppose there is a problem with Apache 2.x. I think it's all about multithreaded mode from Apache 2.x.
Does anyone has a solution for this issue?
Thank you!