Safari adding .html to download

前端 未结 6 1518
南旧
南旧 2021-02-19 07:17

I have a little function, that creates .xls document(using PHPexcel) and then sends it to php://output. Then user download it.
Everything works fine, except that safari on

6条回答
  •  故里飘歌
    2021-02-19 07:42

    I have a similar problem and i solved it with the exit function (used parameter status).

    In model:

    public static function xls($id)
    {
        $xls = new PHPExcel();
        //Code ...
        $objWriter = new \PHPExcel_Writer_Excel5($xls);
    
        ob_start();
        $objWriter->save('php://output');
        $excelOutput = ob_get_clean();
    
        return $excelOutput;
    }
    

    In controller:

    public function xls($id)
    {
        header('Expires: Mon, 1 Apr 1974 05:00:00 GMT');
        header('Last-Modified: ' . gmdate('D,d M YH:i:s') . ' GMT');
        header('Cache-Control: no-cache, must-revalidate');
        header('Pragma: no-cache');
        header('Content-type: application/vnd.ms-excel');
        header('Content-Disposition: attachment; filename=' . $id . '.xls');
    
        return exit(Controller::xls($id)); // <-- 
    }
    

提交回复
热议问题