failed to delete buffer. No buffer to delete

前端 未结 5 1167
再見小時候
再見小時候 2020-12-29 19:46

I am trying to generate an excel file with the extension .xlsx from the code below. I am able to download the file very well but when I open it with excel sheet, I receive t

相关标签:
5条回答
  • 2020-12-29 20:12

    Your code doesn't have ob_start, of course there is no buffer to delete.

    Please checkout http://php.net/manual/en/function.ob-start.php

    0 讨论(0)
  • 2020-12-29 20:13

    Add this piece of code. Happens on live site when minifyhtml is active. Can be connected to advagg and httprl requests.

    Proposed fix is to wrap ob_clean() with ob_get_length() condition.

    if(ob_get_length() > 0) {
        ob_clean();
    }
    
    0 讨论(0)
  • 2020-12-29 20:15

    From the PHP Documentation comment section, credit to cornel at scoalaweb dot com:

    Don't use ob_clean() or ob_end_clean() to clear white-space or other unwanted content "accidentally" generated by included files.

    Included files should not generate unwanted content in the first place.

    If they do, you are doing something wrong, like inserting white-space after "?>" (there should not be a "?>" at the end of PHP files), or other errors who not follow the basic syntax rules of PHP.

    0 讨论(0)
  • 2020-12-29 20:16

    Change

    ob_end_clean();
    

    with this

    if (ob_get_contents()) ob_end_clean();
    
    0 讨论(0)
  • 2020-12-29 20:22

    That error is just telling you that there was no buffer to delete. To avoid it just use:

    if (ob_get_contents()) ob_end_clean();
    

    (check if there's an active output buffer) or:

    if (ob_get_length()) ob_end_clean();
    

    (checks if there's a non empty string in the buffer) as suggested by @Venu.

    also you are calling ob_end_clean(); two times there. And that only works with stackable buffers. From the PHP manual:

    This function discards the contents of the topmost output buffer and turns off this output buffering.

    Are you sure you don't want to just use ob_clean()?

    0 讨论(0)
提交回复
热议问题