这是我的 export_to_excel 助手的代码:
function export_to_excel($query, $filename='exceloutput')
{
$headers = ''; // just creating the var for field headers to append to below
$data = ''; // just creating the var for field data to append to below
$obj =& get_instance();
$fields = $query->list_fields();
if ($query->num_rows() == 0) {
echo '<p>The table appears to have no data.</p>';
} else {
foreach ($fields as $field) {
$headers .= $field . "\t";
}
foreach ($query->result() as $row) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=$filename.xls");
echo "$headers\n$data";
}
}
我在本地主机和服务器上得到不同的结果。当我在 localhost 中运行代码时,它会毫无问题地输出正确的结果,但是当我在服务器上运行代码时,它会给出与 localhost 中相同的结果,但它会添加两行(excel 行),其中包含如下错误:
<br />
<b>Fatal error</b>: ob_start()
[< a href='ref.outcontrol'> ref.outcontrol</a>]:
Cannot use output buffering in output buffering display handlers in
<b>/home/username/public_html/Codeigniter_website/system/core/Exceptions.php</b>
on line <b>181</b><br />
有什么解决办法吗?
这几乎是一个大型项目,这是我在本地和服务器之间看到的唯一区别。