0

im trying to give the user ability to download a specific file. here is my code.

but it keeps adding .txt after the file is downloaded which I want is a .csv

public function downloadCSVSample()
    {

        $file= public_path(). "/downloads/SampleCSV.csv";
        $headers = array(
              'Content-Type: application/csv',
            );
        return Response::download($file, 'SampleCSV.csv', $headers);

    }
Karlo
  • 95
  • 3
  • 9

1 Answers1

0

I'm pretty sure that your browser can't interpret the file. According to this solution, you need to force it to open 'save as...' dialog:

$headers = array(
          'Content-Type: text/csv',
          'Content-disposition: attachment'
);
Community
  • 1
  • 1
Razor
  • 9,577
  • 3
  • 36
  • 51