terminal42 / contao-leads

Leads extension for Contao Open Source CMS; Store and manage form data with ease!
GNU Lesser General Public License v3.0
35 stars 24 forks source link

it exports "txt" file extension, not "csv" #92

Closed math-GH closed 4 years ago

math-GH commented 4 years ago

Contao 4.9.3 Leads 1.4.18

I want to export CSV files grafik

But I get .txt as file extension

fritzmg commented 4 years ago

Contao Leads uses \Contao\File to send the file to the browser, which does not set a Content-Type response header on its own. And somewhere down the pipeline either Contao or Symfony adds the Content-Type: text/plain header.

\Contao\File::sendToBrowser is missing the following:

$response->headers->set('Content-Type', $this->getMimeType());
fritzmg commented 4 years ago

If the Content-Type header is missing, Response::prepare in Symfony's ResponseListener will automatically add it via the FileinfoMimeTypeGuesser which uses PHP Fileinfo. And fileinfo will guess the mime type according to the content of the file, which is just plain text in case of a CSV …

fritzmg commented 4 years ago

Should be fixed in the next Contao versions. See https://github.com/contao/contao/pull/2020