简体   繁体   中英

How can I remove the headers that are exported along with data from the CSV file?

I am working on CSV Export. This file is to be uploaded in ftp server. This is the code I am using to export. It is exporting but along with data it is exporting the header as well. I have added image below.

$now = new DateTime();
$date = $now->format('YmdHis');
$filename = $this->ftpOrderPath. "Order_$date.csv";

$response = new Response();
$response->headers->set('Content-type', 'text/csv');
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename  . '";');
$response->sendHeaders();
$content = $response->setContent($content);


$this->defaultStorage->write($filename, $content);

在此处输入图像描述

Can anybody help me how can I remove those headers from my CSV?

It looks as though it is just dumping the entire Response to the file as text. So I would remove that part and just write the contents directly...

$now = new DateTime();
$date = $now->format('YmdHis');
$filename = $this->ftpOrderPath. "Order_$date.csv";
$this->defaultStorage->write($filename, $content);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM