Laravel: File Download

Viewed 40

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?

3 Answers

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'));

The solution was to do with the Orchid template itself and how it handles AJAX. You're supposed to add ->turbo(false) to the button.

So, the button should look like this:

Button::make('Download Template ')
 ->method('downloadSampleCSV')
 ->turbo(false),

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

Related