[英]phpspreadsheet failed to work on online server! running php version 7.3
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
class ReportExport extends CI_Controller
{
public function download()
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = new Xlsx($spreadsheet);
$filename = 'robert';
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'. $filename .'.xlsx"');
header('Cache-Control: max-age=0');
$writer->save('php://output'); // download file
}
}
I have tried to run that function in codeigniter and i get that response from the browser that File not Found (on the online server) yet when i run it offline(on localhost/) it returns the excel file that i have created.我试图在 codeigniter 中运行该函数,但当我离线运行它时(在 localhost/ 上),我从浏览器中得到文件未找到(在在线服务器上)的响应,它返回我创建的 excel 文件。
Please any ideas i can use to fix the error!请我可以用来修复错误的任何想法!
I am using php version 7.3.14 on the online server.我在在线服务器上使用 php 版本 7.3.14。
Save as file in a deticates Folder on Server在服务器上的特定文件夹中另存为文件
//Path to the file on Server, eg /var/www/website/folder/name.xlsx
$PATH = <PATH>;
$writer->save($PATH);
Firstly, I hope you already resolved this issue.首先,我希望你已经解决了这个问题。
If not, I was getting a similar message, as the online server did not have the ea-php73-php-zip extension installed and it was silently throwing a "PhpSpreadSheet Class ZipArchive not found" error.如果没有,我会收到类似的消息,因为在线服务器没有安装 ea-php73-php-zip 扩展,并且它默默地抛出“找不到 PhpSpreadSheet 类 ZipArchive”错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.