I have created a function in my symfony project that force download a CSV file when click on button based on this answer. The thing is the download works just fine, but the encoding of the file seems to be wrong.
The frensh caracters '
, é
, à
and è
turn into ’
, é
...
my function:
/**
* exportNewsAction
*
* @Route("/getNewsSections", name="newsitem_getNewsSections", options = { "expose" = true })
* @Method({"GET", "POST"})
*/
public function exportNewsAction() {
$path = $this->get('kernel')->getRootDir().'/Resources/files/csvExport';
$csvPath = $path."/News-Item-".$now.".csv";
$response = new Response();
$f = fopen($csvPath, "w");
$titleArray=array('Id', 'Nom', 'Prénom', 'Profile', 'Status', 'Date de création');
fputcsv($f, $titleArray);
// Set headers
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', mime_content_type($csvPath));
$response->headers->set('Content-Disposition', 'attachment; filename="' . basename($csvPath) . '";');
$response->headers->set('Content-length', filesize($csvPath));
// Send headers before outputting anything
$response->sendHeaders();
return $response->setContent(file_get_contents($csvPath));
}
What should I change to get the exact same worlds I used? Any help would be greatly appreciated.