I have downloaded composer successfully and I am trying to use the phpospreadsheet library but I keep getting these errors although this is a basic code. it works on windows but not on linux. Code Sample:
require 'vendor/autoload.php'; use PhpOfficePhpSpreadsheetSpreadsheet; use PhpOfficePhpSpreadsheetWriterXlsx; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('A1', 'Hello World !'); $writer = new Xlsx($spreadsheet); $writer->save('hello world.xlsx');
Errors:
[Tue Oct 05 10:03:34.068348 2021] [php7:warn] [pid 18227] [client 80.247.20.85:62954] PHP Warning: fopen(hello world.xlsx): failed to open stream: Permission denied in /var/www/html/yellow-group.com/public_html/portals/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/BaseWriter.php on line 111 [Tue Oct 05 10:03:34.074664 2021] [php7:error] [pid 18227] [client 80.247.20.85:62954] PHP Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Writer\Exception: Could not open file "hello world.xlsx" for writing. in /var/www/html/yellow-group.com/public_html/portals/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/BaseWriter.php:113nStack trace:n#0 /var/www/html/yellow-group.com/public_html/portals/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php(504): PhpOffice\PhpSpreadsheet\Writer\BaseWriter->openFileHandle('hello world.xls...')n#1 /var/www/html/yellow-group.com/public_html/portals/test.php(13): PhpOffice\PhpSpreadsheet\Writer\Xlsx->save('hello world.xls...')n#2 {main}n thrown in /var/www/html/yellow-group.com/public_html/portals/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/BaseWriter.php on line 113
Advertisement
Answer
the solution was to make a temporary directory. https://github.com/PHPOffice/PhpSpreadsheet/issues/1123
<?php require 'vendor/autoload.php'; use PhpOfficePhpSpreadsheetSpreadsheet; use PhpOfficePhpSpreadsheetWriterXlsx; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('A1', 'Hello World !'); $writer = new Xlsx($spreadsheet); $path='temp/helloworld.xlsx'; $writer->save($path);