Export excel file using PHPExcel working in my loc

2019-09-09 06:04发布

I have a "Download excel file" button in my website. When I click this button, it runs download_header() function. Here is the function's code

public function download_header($pid)
{
    // get pick_list table's field name
    $this->load->model('Download_excel_model');
    $fields = $this->Download_excel_model->table_field_name('pick_list');

    // Starting the PHPExcel library
    $this->load->library('excel');
    $objPHPExcel = new PHPExcel();
    $objPHPExcel->getProperties()->setTitle("export")->setDescription("none");
    $objPHPExcel->setActiveSheetIndex(0);
    // Field names in the first row
    $col = 0;
    foreach ($fields as $field)
    {
        if($field != 'id' && $field != 'status' && $field != 'created_date' && $field != 'updated_date' && $field != 'extra' && $field != 'user_id' && $field != 'pid' && $field != 'qty_scaned')
        {
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field);
            $col++;
        }
    }

    $objPHPExcel->setActiveSheetIndex(0);
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    // Sending headers to force the user to download the file
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="Sample_'.date('dMy').'.xlsx"');
    header('Cache-Control: max-age=0');
    $objWriter->save('php://output');
}

And here is the table_field_name() function's code

public function table_field_name($table)
{
    $query = $this->db->list_fields($table);
    return $query;
}

It's working fine in my localhost and I can download excel file but not working it in live server. it shows this error

This site can’t be reached The webpage at http://dataraceltd.com/demo/bin/download_excel_file/download_header/18 might be temporarily down or it may have moved permanently to a new web address. ERR_INVALID_RESPONSE

Plz Help

1条回答
走好不送
2楼-- · 2019-09-09 07:02

Its seems you have permission related issue on the server. Please first check the write permission on the server.

查看更多
登录 后发表回答