PhpSpreadsheet可能暂时关闭,或者已永久移至新的网址

时间:2019-10-03 07:26:10

标签: php phpexcel phpspreadsheet phpoffice

我正在使用PhpSpreadsheet https://github.com/PHPOffice/PhpSpreadsheet为我的项目生成,并且我正在使用plesk面板和php版本5.6,当我尝试下载excel文件时,我得到了一个错误,该错误可能是暂时关闭的,或者它可能已永久移动。到新的网址。 ERR_INVALID_RESPONSE

我正在使用的代码是

<?php 
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Reader\Html;

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

$rand = md5(rand());
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$rand.'.xlsx"');
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); 
header('Cache-Control: cache, must-revalidate'); 
header('Pragma: public');
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');
exit;

此代码可在其他服务器上运行,但不能在plesk面板上运行

如果我使用

<?php 
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Reader\Html;

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

$rand = md5(rand());
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$rand.'.xlsx"');
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); 
header('Cache-Control: cache, must-revalidate'); 
header('Pragma: public');
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');
exit;

文件已保存到服务器,但我需要将文件下载到浏览器。

在服务器上启用了php扩展名php_zip,php_xml和php gd2。

0 个答案:

没有答案