H
H
Httdientee2021-10-01 10:26:33
Laravel
Httdientee, 2021-10-01 10:26:33

How to implement file download in laravel?

I get an error 500 (if I put in the controller , then everything outputs fine, but the download does not work). controller:return '123';


public static function downdload(Request $request) {
        $file = public_path(). $_POST['link'];

        return Storage::download($file);
    }

Ajax:

$('.this-block a').click(function() {
        $.ajax({
            url: '/ajax/download',
            type: 'POST',
            data: {
                link: $(this).data('link'),
                _token: "<?php echo csrf_token(); ?>"
            },
            success: function( data ) {   
            }
        });
    });

form data:

6156b8274d465151098145.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pLavrenov, 2021-10-01
@pLavrenov

https://qna.habr.com/q/1048894
On the second page of the thread =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question