Adam,
Well thanks to your excellent suggestions we've moved forward somewhat. Now I get 132Mb of my 156Mb download - but still not all of it! The modified code is below. Any other ideas?
<?php
ini_set('max_execution_time', 1200);
ini_set('memory_limit','256M');
set_time_limit(1200);
$path = "../_downloads/"; // change the path to fit your websites document structure
$fullPath = $path.$_GET['file'];
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "zip":
header("Content-type: application/zip"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
stream_set_timeout($fd, 1200);
ob_clean();
flush();
while(!feof($fd)) {
$buffer = fgets($fd,1024);
echo $buffer;
}
}
$info = stream_get_meta_data($fd);
fclose ($fd);
if ($info['timed_out']) {
echo 'Connection timed out!';
} else {
echo 'Done';
}
exit;
// example: place this kind of link into the document where the file download is offered:
// <a href="download.php?file=some_file.pdf">Download here</a>
?>