mk-j / PHP_XLSXWriter

Lightweight XLSX Excel Spreadsheet Writer in PHP
MIT License
1.84k stars 665 forks source link

Not Work Xampp PHP v8.1.6 #335

Closed allweDepth closed 1 year ago

allweDepth commented 2 years ago

I am try to Xampp 8.16 php version 8.1.6 and doesn't work all

allweDepth commented 2 years ago

fix with MAMP packaged by Bitnami php 8.1.11. I do not know why

alex-twbsd commented 1 year ago

I have the same problem. Just need to clear the output buffer before sending HTTP header.

// clear output buffer
ob_end_clean();

header('Content-disposition: attachment; filename="'.rawurlencode($filename).'"; filename*=utf-8\'\''.rawurlencode($filename));
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Cache-Control: max-age=0');
header('Pragma: public');

$writer->writeToStdOut();

I would suggest to add the header output and clear buffer into the writeToStdOut() and change it to:

public function writeToStdOut($filename)
{
    $temp_file = $this->tempFilename();
    self::writeToFile($temp_file);

    // Clear any previous output (otherwise the generated file will be corrupted)
    ob_end_clean();

    header('Content-disposition: attachment; filename="'.rawurlencode($filename).'"; filename*=utf-8\'\''.rawurlencode($filename));
    header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    eader("Content-Length: ".filesize($temp_file));
    header('Cache-Control: max-age=0');
    header('Pragma: public');
    readfile($temp_file);
}
allweDepth commented 1 year ago

Thanks respon @alex-twbsd i Will try your note🙏🏻