我有一个"下载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文件,但不能在实时服务器中使用它。它显示此错误
无法访问此网站 http://dataraceltd.com/demo/bin/download_excel_file/download_header/18的网页可能暂时关闭,或者可能已永久移至新的网址。 ERR_INVALID_RESPONSE
Plz帮助
答案 0 :(得分:1)
它似乎在服务器上有与权限相关的问题。请先检查服务器上的写入权限。