Codeigniter下载文件时收到警告信息

时间:2017-09-29 08:31:56

标签: php codeigniter phpexcel

我现在可以下载PHPExcel文件了。出于某种原因,我得到一个安全警报,说这个文件可能是病毒

enter image description here

  

问题在下面的代码中,我如何确保它不会导致消息显示。

感谢您的时间。

<?php

class Events extends MX_Controller {

    public function generate_excel() {

        $query = $this->db->get('event');
        $excelresults = $query->result_array();

        require (APPPATH . 'third_party/PHPExcel-1.8/Classes/PHPExcel.php');
        require (APPPATH . 'third_party/PHPExcel-1.8/Classes/PHPExcel/Writer/Excel2007.php');

        $objPHPExcel = new PHPExcel();

        $objPHPExcel->getProperties()->setCreator("");
        $objPHPExcel->getProperties()->setLastModifiedBy("");

        $objPHPExcel->getProperties()->setSubject("");
        $objPHPExcel->getProperties()->setCreator("");
        $objPHPExcel->getProperties()->setDescription("");

        $objPHPExcel->setActiveSheetIndex(0);

        $objPHPExcel->getActiveSheet()->SetCellValue("A1", 'Event');
        $objPHPExcel->getActiveSheet()->SetCellValue("B1", 'Event Title');
        $objPHPExcel->getActiveSheet()->SetCellValue("C1", 'Event Date');
        $objPHPExcel->getActiveSheet()->SetCellValue("D1", 'Event Start Time');

        foreach (range('A', $objPHPExcel->getActiveSheet()->getHighestDataColumn()) as $col) {
        $objPHPExcel->getActiveSheet()
                ->getColumnDimension($col)
                ->setAutoSize(true);
        } 

        $excelrow = 2;

        foreach ($excelresults as $excelresult => $excelvalue) {
            $objPHPExcel->getActiveSheet()->SetCellValue("A" . $excelrow, $excelvalue['event']);
            $objPHPExcel->getActiveSheet()->SetCellValue("B" . $excelrow, $excelvalue['event_title']);
            $objPHPExcel->getActiveSheet()->SetCellValue("C" . $excelrow, $excelvalue['event_date']);
            $objPHPExcel->getActiveSheet()->SetCellValue("D" . $excelrow, $excelvalue['event_start_time']);

            $excelrow++;
        }

        $filename = 'Bowling-Events-For-' . date('Y') . '.xlsx';
        $objPHPExcel->getProperties()->setTitle("Riwaka Bowling Club Events");

        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header("Content-Disposition: attachment; filename=".$filename."");
        header("Content-Transfer-Encoding: binary");
        header("Pragma: no-cache");
        header("Expires: 0");
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $objWriter->save('php://output');

        exit();

    }
}

1 个答案:

答案 0 :(得分:1)

FYI

尝试这些标题

header("Content-Type: application/vnd.ms-excel; charset=utf-8"); # Important 
header("Content-Disposition: attachment; filename=abc.xls");  
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);