Read/download PHP 中的大文件没有 运行 内存不足

Read/download large file in PHP without running out of memory

如果 PHP 中没有 运行 的大文件如何 read/download 进入 allowed memory bytes exhausted

我目前正在尝试:

$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;

你试过吗?

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);
}