使用在我本地PC中工作的Phpexcel导出Excel文件,但在Live Server中不起作用



我在我的网站上有一个"下载excel文件"按钮。当我单击此按钮时,它运行download_header()功能。这是函数的代码

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');
}

这是table_field_name()函数的代码

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

它在我的Localhost中工作正常,我可以下载Excel文件,但不能在Live Server中使用它。它显示了此错误

无法联系此网站 http://dataraceltd.com/demo/bin/download_excel_file/download_header/18上的网页可能暂时下降,或者它可能已永久移动到新的网址。 err_invalid_response

plz帮助

它似乎在服务器上有相关问题。请首先检查服务器上的写入权限。

最新更新