gpt4 book ai didi

php - 从 ob_clean 更改为 ob_end_clean?

转载 作者:可可西里 更新时间:2023-10-31 22:43:41 25 4
gpt4 key购买 nike

readfile 的 PHP 文档有一个如何下载文件的示例:

<?php
$file = 'monkey.gif';

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>

它使用 ob_clean 删除可能在输出缓冲区中的内容。

但是我读过的帖子 ( http://heap.tumblr.com/post/119127049/a-note-about-phps-output-buffer-and-readfile ) 指出对于大文件应该使用 ob_end_clean 而不是 ob_clean。

我的问题是:使用 ob_clean 而不是 ob_end_clean 有什么用?如果 ob_end_clean 像 ob_clean 一样工作并且避免了问题,为什么所有文档都没有显示使用 ob_end_clean?

最佳答案

ob_clean() 刷新缓冲区,但保持输出缓冲处于事件状态。这意味着您的 readfile() 输出也将被缓冲。

ob_end_clean() 刷新缓冲区,并完全关闭缓冲,允许 readfile() 直接转储到浏览器。

关于php - 从 ob_clean 更改为 ob_end_clean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21262271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com