问题
I installed phpspreadsheet
with composer in my Codeigniter project. It's working fine on local but throwing an error on the live environment:
This site can’t be reached The webpage at http://www.xxxxxx.com/email/exportemail might be temporarily down or it may have moved permanently to a new web address. ERR_INVALID_RESPONSE
My code:
require(APPPATH . 'vendor/autoload.php');
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
class Email extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function exportemail(){
$customers = $this->sales_model->getCustomerRows();
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0)
->setTitle('Location')
->setCellValue('A1', 'Customer')
->setCellValue('B1', 'Contact name')
->setCellValue('C1', 'Managed by')
->setCellValue('D1', 'Email');
foreach($customers as $key => $customers_data) {
$x = $key + 2;
$spreadsheet->setActiveSheetIndex(0)
->setCellValue("A$x", $customers_data['cust_pub'])
->setCellValue("B$x", $customers_data['ccd_name'])
->setCellValue("C$x", $customers_data['m_name'])
->setCellValue("D$x", $customers_data['cust_pub_email']);
}
$filename = 'Export_Email.xlsx'; //save our workbook as this file name
// Redirect output to a client’s web browser (Xlsx)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');
}
}
Can anyone tell me what changes need to be made on live?
来源:https://stackoverflow.com/questions/50295549/phpspreadsheet-working-on-local-but-not-on-live