php 下载文件 ob_end_clean,PHP: ob_end_clean - Manual

本文探讨了如何在PHP中更有效地实现文件目录搜索,避免使用输出缓冲函数,以提高代码效率。同时指出,即使调用`ob_end_clean()`,`ob_gzhandler()`仍可能设置HTTP头导致内容压缩问题,这在特定情况下可能导致浏览器解压缩失败。解决方案是创建一个`ob_gzhandler`的包装器函数,以确保正确管理内容编码。
摘要由CSDN通过智能技术生成

Keep in mind that mrfritz379's example (#49800) is just an example. You can achieve that example's result in a more efficient manner without using output buffering functions:

echo "

Search running. Please be patient. . .";

$output = "

FileList:

\n";

if (is_dir($dir)) {

$dh = opendir($dir);

while (($fd = readdir($dh)) != false) {

echo " .";

$output .= $fd;

}

}

echo "Search Complete!

\n";

echo $output;

In addition to John Smith's comment (#42939), ob_gzhandler() may still set the HTTP header "Content-Encoding" to "gzip" or "deflate" even if you call ob_end_clean(). This will cause a problem in the following situation:

1. Call ob_gzhandler().

2. Echo "Some content";

3. Call ob_end_clean().

4. Echo "New content";

In the above case, the browser may receive the "Content-Encoding: gzip" HTTP header and attempts to decompress the uncompressed "New content". The browser will fail.

In the following situation, this behaviour will go unnoticed:

1. Call ob_gzhandler().

2. Echo "Some content";

3. Call ob_end_clean().

4. Call ob_gzhandler().

5. Echo "New content";

This is because the second ob_gzhandler() will mask the absence of the first ob_gzhandler().

A solution would be to write a wrapper, like John Smith did, for the ob_gzhandler().

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值