duanji4870 2015-01-15 10:58
浏览 32
已采纳

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

My site is on a shared server, no access to php.ini and output buffering is set as no value.

I have also tried this .htacces but no help (tried without third line as well):

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>

I actually need it as I want to call ob_start() before a header location in middle of a PHP Page as it is sending me - Header already started error.

Thanks in advance.


Also, if someone can help me with a javascript based script which autodownload an exe file on page load (Without any extra page pop up).


Script I am using is:

           // <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条回答 默认 最新

  • duanlang1196 2015-01-15 11:42
    关注

    I think you want that

           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
            }
    

    i prefere to output a normal page with your message and then redirect your user via js to your download.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?