在我的管理仪表板中,我创建了一个自定义模块,用于使用自定义查询进行报告筛选。我需要添加另一个功能,将这些结果导出到CSV。我尝试创建一个非常简单的csv导出示例。
ob_end_clean();
$output .= \'column 1\'. \',\';
$output .= \'column 2\'. \',\';
$output .="\\n";
$output .=\'"data 1",\';
$output .=\'"data 2",\';
$output .="\\n";
$file = "custom_table";
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
echo $output;
不幸的是,它产生了一个错误。
Warning: Cannot modify header information - headers already sent by (output started at C:\\xampp\\htdocs\\rtlcbsasia\\wp-admin\\includes\\template.php:1947) in C:\\xampp\\htdocs\\rtlcbsasia\\wp-content\\plugins\\wpdm-reports\\wpdm-reports.php on line 38
Warning: Cannot modify header information - headers already sent by (output started at C:\\xampp\\htdocs\\rtlcbsasia\\wp-admin\\includes\\template.php:1947) in C:\\xampp\\htdocs\\rtlcbsasia\\wp-content\\plugins\\wpdm-reports\\wpdm-reports.php on line 39
Warning: Cannot modify header information - headers already sent by (output started at C:\\xampp\\htdocs\\rtlcbsasia\\wp-admin\\includes\\template.php:1947) in C:\\xampp\\htdocs\\rtlcbsasia\\wp-content\\plugins\\wpdm-reports\\wpdm-reports.php on line 40
column 1,column 2, "data 1","data 2",
任何帮助都将不胜感激。提前感谢