I had been using PHPExcel
but switched to PHP_xlsxwriter
because of speed. I am really satisfied with the performance but it only works on local server somehow.
$filename = "Report.xls";
$writer->writeToFile($filename);
if (file_exists($filename)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($filename).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filename));
readfile($filename);
unlink($filename);
exit;
}
This is the code and it works completely fine but on server file_exists($filename)
does not catch the condition. And after seeing that I don't even know how it worked on local. How did file_exists
find the file in local server? It does not even have a specific path.
Do I need to specify the path on the server? Could anyone give me an example or an answer to solve this problem? Thanks!
I also had the same problem. The error message I got is like this: "Error: ZipArchive class does not exist\n, referer: http://yoursite..." It happened because I did not have ZipArchive class installed.
See this page for installation instructions. Install it and I hope it will work.