From 825a37d723f65cdc3443440a54c5f342bdc5ded8 Mon Sep 17 00:00:00 2001 From: Prasad <prasad@vtiger.com> Date: Wed, 14 Jun 2023 17:47:25 +0530 Subject: [PATCH] Fixes #1765: Refactored CSV output using php fputcsv --- modules/Vtiger/actions/ExportData.php | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/modules/Vtiger/actions/ExportData.php b/modules/Vtiger/actions/ExportData.php index 503804793..ef3a7fc83 100644 --- a/modules/Vtiger/actions/ExportData.php +++ b/modules/Vtiger/actions/ExportData.php @@ -251,22 +251,12 @@ class Vtiger_ExportData_Action extends Vtiger_Mass_Action { header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" ); header("Cache-Control: post-check=0, pre-check=0", false ); - $header = implode("\", \"", $headers); - $header = "\"" .$header; - $header .= "\"\r\n"; - echo $header; + ob_clean(); + $fp = fopen("php://output", "a+"); + fputcsv($fp, $headers); foreach($entries as $row) { - foreach ($row as $key => $value) { - /* To support double quotations in CSV format - * To review: http://creativyst.com/Doc/Articles/CSV/CSV01.htm#EmbedBRs - */ - $row[$key] = str_replace('"', '""', $value); - } - $line = implode("\",\"",$row); - $line = "\"" .$line; - $line .= "\"\r\n"; - echo $line; + fputcsv($fp, $row); } } @@ -382,4 +372,4 @@ class Vtiger_ExportData_Action extends Vtiger_Mass_Action { public function moduleFieldInstances($moduleName) { return $this->moduleInstance->getFields(); } -} \ No newline at end of file +} -- GitLab