在浏览器中显示csv文件显示错误

时间:2016-03-02 23:17:31

标签: php laravel csv

我试图在浏览器中显示包含数据库数据的csv文件。如果数据库的样本包含200-300行,那么一切都很好!

但是如果在示例中有更多行,那么浏览器中的错误就像:

  

ERR_INVALID_RESPONSE

代码:

public function exportToCSV($id) {
header('Content-Description: File Transfer');
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
//header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename='.LinkFile::find($id)->name.'.csv');
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
$writer = CsvWriter::create('php://output');
$writer->writeLine(['#', 'Link', 'Password', 'Good Task', 'Valid Task']);
$number = 1;
foreach (DB::table("links")->where("user_id", Auth::user()->id)->where("linksFile", $id)->get() as $sfe) {
    if($sfe->isGood == 1) {
        $isGood = "+";
    }
    else {
        $isGood= "-";
    }
    if ($sfe->isValid== 1) {
        $isValid = "+";
    } else {
        $isValid = "-";
    }
    $writer->writeLine([$number, $sfe->link, $sfe->password, $isGood, $isValid], ";", '');
    $number++;
}
echo $writer->flush();
$writer->close();
}

0 个答案:

没有答案