-1

How can I read/download a large file in PHP without running into allowed memory bytes exhausted?

I am currently trying:

$content = null;
while (!feof($file['data'])) {
    $content .= fread($file['data'], 8192);
}

header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"" . $file['real_filename'] . "\"");
header("Content-Length: " . $file['length']);

echo $content;
Justin
  • 42,716
  • 77
  • 201
  • 296
  • Possible duplicate of [How to echo the whole content of an .html file in php?](https://stackoverflow.com/questions/9539849/how-to-echo-the-whole-content-of-an-html-file-in-php) – Nigel Ren May 08 '18 at 05:53

1 Answers1

1

Have you tried this ?

header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"" . $file['real_filename'] . "\"");
header("Content-Length: " . $file['length']);

while (!feof($file['data'])) {
    print fread($file['data'], 8192);
}