phpspreadsheets/phpoffice 无法在 linux 上运行
phpspreadsheets/ phpoffice not working on linux
我已经成功下载了 composer,我正在尝试使用 phpospreadsheet 库,但我不断收到这些错误,尽管这是一个基本代码。它适用于 windows 但不适用于 linux。
代码示例:
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = new Xlsx($spreadsheet);
$writer->save('hello world.xlsx');
错误:
[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:113\nStack 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
解决方案是制作一个临时目录。 https://github.com/PHPOffice/PhpSpreadsheet/issues/1123
<?php
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = new Xlsx($spreadsheet);
$path='temp/helloworld.xlsx';
$writer->save($path);
我已经成功下载了 composer,我正在尝试使用 phpospreadsheet 库,但我不断收到这些错误,尽管这是一个基本代码。它适用于 windows 但不适用于 linux。 代码示例:
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = new Xlsx($spreadsheet);
$writer->save('hello world.xlsx');
错误:
[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:113\nStack 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
解决方案是制作一个临时目录。 https://github.com/PHPOffice/PhpSpreadsheet/issues/1123
<?php
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = new Xlsx($spreadsheet);
$path='temp/helloworld.xlsx';
$writer->save($path);