Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
incorrect csv file name after download from controller
  1. What needs to be changed so that the name of the file after downloading is the same as I indicated

  2. Why the file type is not detected on Windows and Linux. (on macos the extension is defined)

I do not save the file on the server, but I generate data on the fly and send it to the new Response() After downloading, the file does not have the name that I want, it also does not show the file extension on Windows

    public function download(Request $request): Response
    {
        $array = [];

       /// filling the array

        $serializer = new Serializer([new ObjectNormalizer()], [new CsvEncoder()]);
        $csv = $serializer->encode($array, 'csv', [CsvEncoder::DELIMITER_KEY => ';', CsvEncoder::OUTPUT_UTF8_BOM_KEY => true]);

        $response = new Response($csv);
        $disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, "desiredFilename.csv");
        $response->headers->set('Content-Type', 'text/csv; charset=UTF-8');
        $response->headers->set('Content-Disposition', $disposition);

        return $response;
    }

file name after downloading like e9ddc45c-f3b6-404d-8251-ee51bc488c6e.csv

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

regarding The MDN Doc you need to include your filename in the double quotations filename="desiredFilename.csv" .

I think maybe you have to wrap the file name into it:

        $disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, '"desiredFilename.csv"');

FYI: I have seen the Symphony Docs and it's example is like what you have provided.

over 4 years ago · Santiago Trujillo Report

0

You can try this :

$response->header->set('Content-Disposition: attachment; filename="desiredFilename.csv"');

I think this link can be useful: Symfony Docs

Enjoy !

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!