PHP downloading excel file blank using frames












0















I have a frame with a header containing some buttons (list, pdf and excel). Under the header it lists data from db. It works fine with listing option but when I try to download excel file it comes blank with the following message:




Resource interpreted as Document but transferred with MIME type
application/force-download




I've searched through the internet and tried some other functions but nothing has helped.



php:



frames.php



<!DOCTYPE>
<frameset bordercolor="#3399CC" rows="30,*">
<frame name="header" id="header" src="header.php" scrolling="no" noresize>
<frame name="List" id="List">
<noframes>
</html>
<body style="margin:0px;">
</body>
</html>
</noframes>
</frameset>


ranking.php



if ($tp==4){ // tp 4 is from excel button option
header("Content-type: application/vnd.ms-excel");
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=Rel.xls");
header("Pragma: no-cache");
echo $html;
}


header.php



<input type="button" value="Excel" id="Excel" name="Excel" onClick="javascript: List(4);" class="FlatDActv" onMouseOver="this.className='FlatActv';" onMouseOut="this.className='FlatDActv';" style="position: relative; width: 50">


function List(tp){

window.open('ranking.php?tp='+tp+'&cd_tipo='+document.getElementById('cd_tipo').value+'&dt_de='+document.getElementById('dt_de').value+'&dt_ate='+document.getElementById('dt_ate').value, "List");

}









share|improve this question























  • Where is $html generated? If it is, in fact, HTML (as the variable name indicates), then that's likely your problem. The browser knows that, despite what your headers say, you're really sending a regular HTML document.

    – Patrick Q
    Jan 2 at 18:57













  • $html lists the results from db after download has started/finished

    – A52
    Jan 2 at 19:16











  • That really doesn't answer/address my question. You should include the code that generates $html. If you are not actually creating an XML document, you shouldn't tell your browser to expect one.

    – Patrick Q
    Jan 2 at 19:19











  • Sorry. My $html concatenates a big table with a lot of data and it is like $html .= "<table>"; $html .= "<tr>......"; $html .= "</table>";

    – A52
    Jan 2 at 19:30











  • the echo $html; lists that table after download

    – A52
    Jan 2 at 19:47
















0















I have a frame with a header containing some buttons (list, pdf and excel). Under the header it lists data from db. It works fine with listing option but when I try to download excel file it comes blank with the following message:




Resource interpreted as Document but transferred with MIME type
application/force-download




I've searched through the internet and tried some other functions but nothing has helped.



php:



frames.php



<!DOCTYPE>
<frameset bordercolor="#3399CC" rows="30,*">
<frame name="header" id="header" src="header.php" scrolling="no" noresize>
<frame name="List" id="List">
<noframes>
</html>
<body style="margin:0px;">
</body>
</html>
</noframes>
</frameset>


ranking.php



if ($tp==4){ // tp 4 is from excel button option
header("Content-type: application/vnd.ms-excel");
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=Rel.xls");
header("Pragma: no-cache");
echo $html;
}


header.php



<input type="button" value="Excel" id="Excel" name="Excel" onClick="javascript: List(4);" class="FlatDActv" onMouseOver="this.className='FlatActv';" onMouseOut="this.className='FlatDActv';" style="position: relative; width: 50">


function List(tp){

window.open('ranking.php?tp='+tp+'&cd_tipo='+document.getElementById('cd_tipo').value+'&dt_de='+document.getElementById('dt_de').value+'&dt_ate='+document.getElementById('dt_ate').value, "List");

}









share|improve this question























  • Where is $html generated? If it is, in fact, HTML (as the variable name indicates), then that's likely your problem. The browser knows that, despite what your headers say, you're really sending a regular HTML document.

    – Patrick Q
    Jan 2 at 18:57













  • $html lists the results from db after download has started/finished

    – A52
    Jan 2 at 19:16











  • That really doesn't answer/address my question. You should include the code that generates $html. If you are not actually creating an XML document, you shouldn't tell your browser to expect one.

    – Patrick Q
    Jan 2 at 19:19











  • Sorry. My $html concatenates a big table with a lot of data and it is like $html .= "<table>"; $html .= "<tr>......"; $html .= "</table>";

    – A52
    Jan 2 at 19:30











  • the echo $html; lists that table after download

    – A52
    Jan 2 at 19:47














0












0








0








I have a frame with a header containing some buttons (list, pdf and excel). Under the header it lists data from db. It works fine with listing option but when I try to download excel file it comes blank with the following message:




Resource interpreted as Document but transferred with MIME type
application/force-download




I've searched through the internet and tried some other functions but nothing has helped.



php:



frames.php



<!DOCTYPE>
<frameset bordercolor="#3399CC" rows="30,*">
<frame name="header" id="header" src="header.php" scrolling="no" noresize>
<frame name="List" id="List">
<noframes>
</html>
<body style="margin:0px;">
</body>
</html>
</noframes>
</frameset>


ranking.php



if ($tp==4){ // tp 4 is from excel button option
header("Content-type: application/vnd.ms-excel");
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=Rel.xls");
header("Pragma: no-cache");
echo $html;
}


header.php



<input type="button" value="Excel" id="Excel" name="Excel" onClick="javascript: List(4);" class="FlatDActv" onMouseOver="this.className='FlatActv';" onMouseOut="this.className='FlatDActv';" style="position: relative; width: 50">


function List(tp){

window.open('ranking.php?tp='+tp+'&cd_tipo='+document.getElementById('cd_tipo').value+'&dt_de='+document.getElementById('dt_de').value+'&dt_ate='+document.getElementById('dt_ate').value, "List");

}









share|improve this question














I have a frame with a header containing some buttons (list, pdf and excel). Under the header it lists data from db. It works fine with listing option but when I try to download excel file it comes blank with the following message:




Resource interpreted as Document but transferred with MIME type
application/force-download




I've searched through the internet and tried some other functions but nothing has helped.



php:



frames.php



<!DOCTYPE>
<frameset bordercolor="#3399CC" rows="30,*">
<frame name="header" id="header" src="header.php" scrolling="no" noresize>
<frame name="List" id="List">
<noframes>
</html>
<body style="margin:0px;">
</body>
</html>
</noframes>
</frameset>


ranking.php



if ($tp==4){ // tp 4 is from excel button option
header("Content-type: application/vnd.ms-excel");
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=Rel.xls");
header("Pragma: no-cache");
echo $html;
}


header.php



<input type="button" value="Excel" id="Excel" name="Excel" onClick="javascript: List(4);" class="FlatDActv" onMouseOver="this.className='FlatActv';" onMouseOut="this.className='FlatDActv';" style="position: relative; width: 50">


function List(tp){

window.open('ranking.php?tp='+tp+'&cd_tipo='+document.getElementById('cd_tipo').value+'&dt_de='+document.getElementById('dt_de').value+'&dt_ate='+document.getElementById('dt_ate').value, "List");

}






javascript php excel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 18:53









A52A52

116




116













  • Where is $html generated? If it is, in fact, HTML (as the variable name indicates), then that's likely your problem. The browser knows that, despite what your headers say, you're really sending a regular HTML document.

    – Patrick Q
    Jan 2 at 18:57













  • $html lists the results from db after download has started/finished

    – A52
    Jan 2 at 19:16











  • That really doesn't answer/address my question. You should include the code that generates $html. If you are not actually creating an XML document, you shouldn't tell your browser to expect one.

    – Patrick Q
    Jan 2 at 19:19











  • Sorry. My $html concatenates a big table with a lot of data and it is like $html .= "<table>"; $html .= "<tr>......"; $html .= "</table>";

    – A52
    Jan 2 at 19:30











  • the echo $html; lists that table after download

    – A52
    Jan 2 at 19:47



















  • Where is $html generated? If it is, in fact, HTML (as the variable name indicates), then that's likely your problem. The browser knows that, despite what your headers say, you're really sending a regular HTML document.

    – Patrick Q
    Jan 2 at 18:57













  • $html lists the results from db after download has started/finished

    – A52
    Jan 2 at 19:16











  • That really doesn't answer/address my question. You should include the code that generates $html. If you are not actually creating an XML document, you shouldn't tell your browser to expect one.

    – Patrick Q
    Jan 2 at 19:19











  • Sorry. My $html concatenates a big table with a lot of data and it is like $html .= "<table>"; $html .= "<tr>......"; $html .= "</table>";

    – A52
    Jan 2 at 19:30











  • the echo $html; lists that table after download

    – A52
    Jan 2 at 19:47

















Where is $html generated? If it is, in fact, HTML (as the variable name indicates), then that's likely your problem. The browser knows that, despite what your headers say, you're really sending a regular HTML document.

– Patrick Q
Jan 2 at 18:57







Where is $html generated? If it is, in fact, HTML (as the variable name indicates), then that's likely your problem. The browser knows that, despite what your headers say, you're really sending a regular HTML document.

– Patrick Q
Jan 2 at 18:57















$html lists the results from db after download has started/finished

– A52
Jan 2 at 19:16





$html lists the results from db after download has started/finished

– A52
Jan 2 at 19:16













That really doesn't answer/address my question. You should include the code that generates $html. If you are not actually creating an XML document, you shouldn't tell your browser to expect one.

– Patrick Q
Jan 2 at 19:19





That really doesn't answer/address my question. You should include the code that generates $html. If you are not actually creating an XML document, you shouldn't tell your browser to expect one.

– Patrick Q
Jan 2 at 19:19













Sorry. My $html concatenates a big table with a lot of data and it is like $html .= "<table>"; $html .= "<tr>......"; $html .= "</table>";

– A52
Jan 2 at 19:30





Sorry. My $html concatenates a big table with a lot of data and it is like $html .= "<table>"; $html .= "<tr>......"; $html .= "</table>";

– A52
Jan 2 at 19:30













the echo $html; lists that table after download

– A52
Jan 2 at 19:47





the echo $html; lists that table after download

– A52
Jan 2 at 19:47












1 Answer
1






active

oldest

votes


















0














I solved it just adding



if($tp==4){
ob_clean();
}


before $html tags to clear the extra data when loading the file






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011678%2fphp-downloading-excel-file-blank-using-frames%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I solved it just adding



    if($tp==4){
    ob_clean();
    }


    before $html tags to clear the extra data when loading the file






    share|improve this answer




























      0














      I solved it just adding



      if($tp==4){
      ob_clean();
      }


      before $html tags to clear the extra data when loading the file






      share|improve this answer


























        0












        0








        0







        I solved it just adding



        if($tp==4){
        ob_clean();
        }


        before $html tags to clear the extra data when loading the file






        share|improve this answer













        I solved it just adding



        if($tp==4){
        ob_clean();
        }


        before $html tags to clear the extra data when loading the file







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 18 at 20:57









        A52A52

        116




        116
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011678%2fphp-downloading-excel-file-blank-using-frames%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith