Please tell me how to implement the functionality. The site has a form, after submitting the form, the script should:

  1. process data

  2. give pdf document to download to user

  3. redirect the user to the page with thanks

With the first point everything is fine, the problem appeared with the last two

$filename = './handbook.pdf'; header("Content-type: application/x-download"); header("Content-Disposition: attachment; filename=$filename"); readfile($filename); header( 'Location: ../end.html', true, 301 ); 

The function header () can be called if data has not yet been transmitted to the client, but there has already been data transfer.

Help implement the functionality

Thank!

    1 answer 1

    If you need to use only PHP, then you can use a delay in header ():

      header("refresh:3;url=https://google.com/"); 

    That is, the redirect will pass not immediately, but with a delay (3 seconds). Until then, you can display data in the browser. The header () itself should naturally be sent before any output to the browser.

    • I transfer the file to upload via header (), this option will not work - Dmitry