dpzbzp8728 2014-11-18 06:58
浏览 32

为什么我的CSV文件没有正确编写并通过PHP脚本下载

I'm trying to get the contents of a existing CSV file to another CSV and download, but currently it doesn't write the data inside the existing CSV file correctly

My Code:

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"report.csv\"");
$f_pointer=fopen("result.csv","r"); // file pointer

while(!feof($f_pointer)) {
  $data=fgetcsv($f_pointer);
  echo $data;
}

What it returns:

> > <br /> <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'> <tr><th
> align='left' bgcolor='#f57900' colspan="5"><span
> style='background-color: #cc0000; color: #fce94f; font-size:
> x-large;'>( ! )</span> Notice: Array to string conversion in
> C:\xampp\htdocs\162\dld1.php on line <i>9</i></th></tr> <tr><th
> align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
> <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left'
> bgcolor='#eeeeec'>Time</th><th align='left'
> bgcolor='#eeeeec'>Memory</th><th align='left'
> bgcolor='#eeeeec'>Function</th><th align='left'
> bgcolor='#eeeeec'>Location</th></tr> <tr><td bgcolor='#eeeeec'
> align='center'>1</td><td bgcolor='#eeeeec'
> align='center'>0.0000</td><td bgcolor='#eeeeec'
> align='right'>135152</td><td bgcolor='#eeeeec'>{main}(  )</td><td
> title='C:\xampp\htdocs\162\dld1.php'
> bgcolor='#eeeeec'>..\dld1.php<b>:</b>0</td></tr> </table></font>

What I want returned instead:

17  testproject TDD 1   2   27  10/13/2014 10:19    10/2/2014 7:25  Win7    Windows Desktop Firefox 33
17  testproject DTD 1   2   27  10/13/2014 10:19    10/2/2014 7:25  Win7    Windows Desktop Firefox 33

My CSV file:

tID tname       accountname accountid   status  imprcount   earliest_imp        recent_imp       platform   device          browser browser_version
17  testproject TDD         1           2       27          10/13/2014 10:19    10/2/2014 7:25   Win7       Windows Desktop Firefox 33
17  testproject DTD         1           2       27          10/13/2014 10:19    10/2/2014 7:25   Win7       Windows Desktop Firefox 33
  • 写回答

1条回答 默认 最新

  • dongsheng4679 2014-11-18 07:01
    关注

    change

    echo $data;
    

    to

    var_dump($data);
    

    the problem is cause by the fgetcsv() because it returns an array and not string

    http://php.net/manual/en/function.fgetcsv.php

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?