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 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型