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

时间:2015-01-15 10:58:38

标签: php .htaccess

我的网站位于共享服务器上,无法访问php.inioutput 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页面中间的标题位置之前调用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");
            }

1 个答案:

答案 0 :(得分:0)

我想你想要那个

       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将您的用户重定向到您的下载。