首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何通过htaccess或output_buffering设置"PHP output_buffering On“?

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

Stack Overflow用户
提问于 2015-01-15 10:58:38
回答 1查看 1.2K关注 0票数 0

我的站点位于共享服务器上,没有访问php.ini的权限,output buffering设置为no value

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

代码语言:javascript
复制
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>

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

提前谢谢。

另外,如果有人可以帮助我完成一个基于javascript的脚本,它可以在页面加载时自动下载一个exe文件(没有任何额外的页面弹出)。

我正在使用的脚本是:

代码语言:javascript
复制
           // <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");
            }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-15 11:42:17

我想你想要那个

代码语言:javascript
复制
       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将用户重定向到您的下载。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27961886

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档