开发者

Output buffering incorrects further code

开发者 https://www.devze.com 2023-04-04 18:43 出处:网络
Currently I have a dynamic CSS file, completed by PHP from results in the database. At the moment I\'m converting the dynamic files into static files using output buffering. The conversion to a static

Currently I have a dynamic CSS file, completed by PHP from results in the database. At the moment I'm converting the dynamic files into static files using output buffering. The conversion to a static file works like a charm but the action is called from a jQuery dialogwindow. After the operation is completed a small piece of HTML is printed to close the dialogform.

In here lies the problem. The HTML code gets printed instead of parsed. I believe it's because of the output buffrering. When I comment the buffering code everything works again.

Can someone tell me what's going wrong?

The code in the OB im using is:

ob_start();
$MC_ParseTemplateCall = 1;  # is used in the include to set some values         
require_once($Template); # Template contains the path and filename
$templateCss = ob_get_contents(); #using this to store it with fopen, fwrite & fclose
ob_end_clean();

Additional info:

From a file like save.php (which is executed in a jQuery dialog)

<?php
    // stuff to save template related settings happens above

    # Make a static CSS file
    ParseAndStoreTemplate(DIR_PATH_TO_ROOT."../website/Templates/MyTpl2011/CSS/MyTpl2011.php");
?>
<html>
    <body onLoad="window.parent.CloseDialog();"></body>
</html> 

Function to store the template:

function ParseAndStoreTemplate($Template)
{
    if(is_file($Template))
    {
        ob_start();
        $MC_ParseTemplateCall = 1;              
        require_once($Template);
        $templateCss = ob_get_contents();
        ob_end_clean();

        $fileName   = end(explode("/", $Template));
        $templateName   = reset(explode(".php", $fileName));
        $websitePath    = DIR_PATH_TO_ROOT."../Global/Files/Website/".$GLOBALS["WebsiteId"]."/";
        $templateFolder = "CSS";

        if(!is_dir($websitePath.$templateFolder))
            mkdir($websitePath.$templateFolder);

        file_put_contents(  
            $websitePath.$templateFolder."/".$templateName,
 开发者_StackOverflow中文版           $templateCss);
    }
    else
        die("<strong>Opgegeven templatebestand bestaat niet</strong>: ".$Template);
}


Figured it out already. It seemed that the Content-Type header gets changed during output buffering. After telling the browser it should behave like a text/html page the dialog gets closed again like it should. Thanks anyway!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号