Home > Enterprise >  Laravel: File Download
Laravel: File Download

Time:09-21

I have a download script like this:

    public function downloadSampleCSV(){
        $file = public_path()."/downloads/Payout example file.csv";
        $headers = array('Content-Type: text/csv',);
        return Response::download($file, 'Payout example file.csv',$headers);
    }

The file path is correct and the Network panel even outputs the content of the file, but the file doesn't actually get downloaded from the browser.

Here's what the Network panel shows. You can tell it's found the file but just doesn't proceed to downloading it: Network panel

What could be the issue?

CodePudding user response:

allows file downloads with response()->download() to return file for download. We no longer need to mess with any headers. To return a file we simply:

return response()->download(public_path('/downloads/Payoutexamplefile.csv'));

CodePudding user response:

Why you are not using this in your blade file? <a href="{{ asset('/downloads/Payout example file.csv') }}" download> Download File </a>

  • Related