dtxw20878 2014-03-26 13:40
浏览 277

从PHP创建CSV文件,没有换行符

I am trying to create a CSV file from my web page and am having issue with line feeds/carraige returns.

I am building up the CSV string via Javascript and then adding '\u000A' + "\u000D" to the end of each line.

I then pass my CSV sting to a PHP program via AJAX. My PHP logic to create the file is: -

header('Content-Disposition: attachment; filename="effortTool.csv"');
header('Content-Type: text/plain');
header('Content-Length: ' . strlen($content));

When I view the file it does not contain any line feeds/carraige retuns.

If I output the CSV string as an "alert", I can see it is formatting corerctly. This tells me that the line feeds characters are being added but are being lost when downloaded as a file.

Any ideas?

Thanks

Martin

  • 写回答

2条回答 默认 最新

  • ds78662302 2014-03-26 13:45
    关注

    You put the file content on the meta data of type Content-Length, this is wrong.

    Try this: php download file: header()

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!