Serving files (800MB) results in an empty file
Posted
by azz0r
on Stack Overflow
See other posts from Stack Overflow
or by azz0r
Published on 2010-03-26T16:33:06Z
Indexed on
2010/03/26
17:03 UTC
Read the original article
Hit count: 110
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;
}
}
© Stack Overflow or respective owner