mercredi 3 juillet 2019

How to run code after response()->download(in POST control

In my laravel 5.8 app I managed to generate filw with help of https://github.com/spatie/browsershot and downloading it in a control:

$save_to_file = 'generate_profile_card_' . Session::getId() . '_' . $filename_to_save;

if ( strtolower($option_output_file_format) == 'pdf' ) {
    Browsershot::html(htmlspecialchars_decode($pdf_content))
        ->showBackground()
        ->save($save_to_file);
    \Response::download( $save_to_file, $save_to_file, array('Content-Type: application/octet-stream','Content-Length: pdf') );
    return response()->download( $save_to_file, $filename_to_save );

I generate unique name in $save_to_file var and file is downloading ok, but in the control method above I return with download method, but I also need: 1) remove downloaded $save_to_file file 2) redirect with message that downloading was successfull. That seems tricky, as this control method needs return . If to commect last return...

the file is not downloaded at all. This control method is submitted by by form submit:

<form method="POST" action="" accept-charset="UTF-8" id="form_print_to_pdf_content" name="form_print_to_pdf_content"
          enctype="multipart/form-data">
        {!! csrf_field() !!}

If there is a way to run some code after
return response()->download( $save_to_file, $filename_to_save );

on successfull download ?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2xt32Ej
via IFTTT

Aucun commentaire:

Enregistrer un commentaire