Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda