I have this remote Windows 2012 (see last edit) server with latest xampp installed.
The users can normally download files (small and very big ones) from there but there are some files (pdf and zips containing the same pdfs, but not rar with the same files inside) whose download stops always at the same size.
Basically the download start normally but at a certain size, always the same on the same file, it hang for a while then stop.
This is the current code:
header("X-Sendfile: ".$pathTofile);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$filename\"");
Some things I'm sure of:
- File size does not matter. The problem show either with big or small files and I've non problem with other very big files
- I'v tried at least 5 different php scripts all with the same result
- I've implemented xsendfile. Same result
- If I try to view the pdf in the browser, it won't work either
- If I download the files directly from the server they work properly in every aspect
- I've tried different browser and different ISP. Same result
- If I do the same operation on the site, but locally on server, everything works perfectly
EDIT:
I've changed webserver in favor of Uniform Server (see last edit) and was tryng another php script:
function send_file($position, $name) {
ob_end_clean();
$path = $position.$name;
if (!is_file($path) or connection_status()!=0) return(FALSE);
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
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("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Content-Type: application/octet-stream");
$filesize=filesize($path);
header("Content-Length: ".$filesize);
header("Content-Disposition: inline; filename=$name");
header("Content-Transfer-Encoding: binary\n");
if ($file = fopen($path, 'rb')) {
while(!feof($file) and (connection_status()==0)) {
print(fread($file, 1024*8));
flush();
}
fclose($file);
}
return((connection_status()==0) and !connection_aborted());
}
Strangley the page ignored the Content-Length header and the download worked!!
Even more strangley, I've tried to made Content-Length working by adding this line:
header("Content-Range: 0-".($filesize-1)."/".$filesize);
or/and disabling gzip compression like this:
apache_setenv('no-gzip', '1');
in both cases the Content-Length worked but the download stopped at the same point!!!
It's driving me crazy!!!
EDIT 23-10-2018: we recently switch on a debian server with fresh apache installation. The problem seems to remain. I've also try the same identical script on a shared webserver from a local provider and surprisingly it work perfectly. Any help appreciated....