phpspreadsheet working on local but not on live

送分小仙女□ 提交于 2020-01-06 04:32:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!