如何通过htaccess或PHP设置"PHP output_buffering On"?

How to set "PHP output_buffering On" through htaccess or PHP?

我的站点在共享服务器上,无法访问 php.ini 并且 output buffering 设置为 no value

我也试过这个 .htacces 但没有帮助(没有第三行也试过):

1.   <IfModule mod_php5.c>
2.   php_flag output_buffering On
3.   php_value output_buffering 8192
4.   php_value output_handler mb_output_handler
5. </IfModule>

我实际上需要它,因为我想在 PHP 页面中间的 header 位置之前调用 ob_start(),因为它正在向我发送 - Header already started error

提前致谢。


此外,如果有人可以帮助我提供基于 javascript 的脚本,该脚本会在页面加载时自动下载 exe 文件(不会弹出任何额外页面)。


我使用的脚本是:

           // <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
           .
           .
           .
           // Sending Mails and other stuff

           if ($mail->send()) {
                $alertSuccess = 1;
                $alertMsg = "Your license has been sent succesfully.";

                ## Download Installer
                $folder = "license";
                $file = "Setupn.msi";
                ob_start();
                header("Content-disposition: attachment; filename=$file");
                header("Content-type: application/octet-stream");
                ob_clean();
                flush();
                readfile("$folder/$file");
            }

我想你想要那个

       if ($mail->send()) {
            $alertSuccess = 1;
            $alertMsg = "Your license has been sent succesfully.";

            ## Download Installer
            $folder = "license";
            $file = "Setupn.msi";
            ob_clean(); // clear your current output and set headers for your download
            // its not possible to remove already setted headers with ob_clean
            header("Content-disposition: attachment; filename=$file");
            header("Content-type: application/octet-stream");
            flush();
            readfile("$folder/$file");
            exit; // i prefere an exit here, to stop all other scripts
        }

我更喜欢用您的消息输出一个普通页面,然后通过 js 将您的用户重定向到您的下载。