CSV file not download

hello I try to download csv but it not working

$results = $this->getDoctrine()->getManager()->getRepository(‘AppBundle:Platform’)->findAll();

    $response = new StreamedResponse();
    $response->setCallback(
        function () use ($results) {
            $handle = fopen('php://output', 'w+');
            foreach ($results as $row) {
                //array list fields you need to export
                $data = array(
                    $row->getId(),
                    $row->getPtfLogo(),
                    $row->getCreatedAt(),
                    $row->getUpdatedAt(),
                    $row->getPtfName()
                );
                fputcsv($handle, $data, ';', '"');
            }
            fclose($handle);
        }
    );
    //dump($response);die;
    $response->headers->set('Content-Encoding', 'UTF-8');
    $response->headers->set('Content-Type', 'text/csv');
    $response->headers->set('Content-Disposition', 'attachment; filename="platformes.csv"');

    //dump($response);die;
    return $response;

do nothing

fputcsv($handle, $data, ';', '"');

delete this line download with blank csv

please help

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *