Reputation: 21
So I made this program to export data from database into excel format with PHP language and library called PHPSpreadsheet. In localhost the program works fine. But in online server the program is not working. Does this have issue with PHP version, cause in my localhost, it's PHP 7.2 but in online server is 7.0.
Is there any other library for export excel with PHP version 7.0? I have tried PHPExcel but they said its deprecated for php 7.x
<?php
require_once("vendor/autoload.php");
require_once('../../connection.php');
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
// other code
// export excel
$writer = new Xlsx($spreadsheet);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition: attachment; filename=Pusdiklat - ".$data_diklat->nama.".xls");
$writer->save("php://output");
// display error
ini_set('display_errors','1');
ini_set('display_startup_errors','1');
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT)
?>
I have tried to display the error and the export worked but when I opened the excel it shows error. Here is the error:
Warning: ZipArchive::close(): Failure to create temporary file: No such file or directory in /home/admin/web/domain.com/public_html/admin/data/daftar_diklat/excel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php on line 409
Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Writer\Exception: Could not close zip file php://output. in /home/admin/web/domain.com/public_html/admin/data/daftar_diklat/excel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php:410 Stack trace: #0 /home/admin/web/domain.com/public_html/admin/data/daftar_diklat/excel/export_pusdiklat.php(139): PhpOffice\PhpSpreadsheet\Writer\Xlsx->save('php://output') #1 {main} thrown in /home/admin/web/domain.com/public_html/admin/data/daftar_diklat/excel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php on line 410
And this is my server:
PHP 7.0.33-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.33-0ubuntu0.16.04.3, Copyright (c) 1999-2017, by Zend Technologies
Upvotes: 1
Views: 2861
Reputation: 875
The support of PHP 7.0 was dropped at Version 1.9.0.
Upvotes: 2