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 xshell无法连接提示ssh服务器拒绝密码
  • ¥15 AT89C52单片机C语言关于串口通信的位操作
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?