我使用AWS服务器选择ubuntu并安装vestacp管理面板。我用的是Apache2和php版本7.0 ..... 我遇到问题创建excel文件下载。我更改了php.ini和.htaccess文件的内存限制,但没有解决此错误。请帮助你。 这是我用来创建excel文件下载的代码。
消息:允许的内存大小为33554432字节已用尽(尝试分配4096字节)
public function coupon(){
ini_set('memory_limit','128M');
$this->load->library('Classes/PHPExcel');
$queryexport = "select * from tbl_coupons";
$query = $this->m_export->executeDbQuery($queryexport);
// Instantiate a new PHPExcel object
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("export")->setDescription("none");
$objPHPExcel->setActiveSheetIndex(0);
// Field names in the first row
$fields = $query->list_fields();
$col = 0;
foreach ($fields as $field)
{
if($field == 'update_time'){
continue;
}
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, stripslashes($field));
$col++;
}
//pr($fields);die;
// Fetching the table data
$row = 2;
foreach($query->result() as $data)
{
$col = 0;$id = 0;
foreach ($fields as $field)
{
if($field == 'update_time'){
continue;
}
if($field == 'id'){
$id = $data->$field;
}
if($field == 'categories'){
$storeCategories = getCouponCategories($id);
$arrCategoryIds = implode(',', $storeCategories);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $arrCategoryIds);
}else{
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, stripslashes($data->$field));
}
$col++;
}
$row++;
}
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$filename = "couponexcel_" . date('Ymd') . ".xls";
// Sending headers to force the user to download the file
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
}