Hello, with the following code, small files are served fine, however large (see, 800MB and above) result in empty files!
Would I need to do something with apache to solve this?
<?php
class Model_Download {
function __construct($path, $file_name) {
$this->full_path = $path.$file_name;
}
public function execute() {
if ($fd = fopen ($this->full_path, "r")) {
$fsize = filesize($this->full_path);
$path_parts = pathinfo($this->full_path);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // 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"]."\"");
break;
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
}
}
Edit: If I use
fpassthru($fd); exit;
instead, I get the following written inside a file:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 786032641 bytes) in /Users/aaron/Sites/com/library/Model/Download.php on line <i>44