In php Instead of downloading csv file it gets open in the browser

后端 未结 4 634
梦毁少年i
梦毁少年i 2021-01-16 09:33

I\'m trying to download a CSV file through the browser. The script is partially working, because so far I managed to display the CSV on screen, but the download is not start

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-16 09:42

    I can tell you this combination is working for me:

    $bom = chr(0xEF) . chr(0xBB) . chr(0xBF);
    header("Content-type: application/csv; charset=UTF-8");
    header("Content-Disposition: attachment; filename=$filename.csv");
    header("Pragma: no-cache");
    header("Expires: 0");
    print $bom . $data;
    exit;
    

    If I were you, I would first test this plainly (outside of all your buffering), first see that you manage to make this work, and only then test it in your specific set up.

提交回复
热议问题