in reply to Re: Perl CGI download file and redirect
in thread Perl CGI download file and redirect

Didn't I have to print headers first? If I print the header the file download is starting directly. How am I supposed to print first html then starting the download?

  • Comment on Re^2: Perl CGI download file and redirect

Replies are listed 'Best First'.
Re^3: Perl CGI download file and redirect
by Corion (Patriarch) on Nov 17, 2014 at 14:35 UTC

    Oh, sorry - I glossed over that part. You need a separate URL for sending the download. There you send the download headers. You have the URL for the "thank you" HTML page. There, you display the "thank you" message and then redirect (using META tags or Javascript) to the download page:

    <html> <head> <meta http-equiv="refresh" content="5; url=download.pl?filename=$p_fil +ename.pdf"> <body> <h1>Thank you!</h1> </body> </html>

      I'm reffering from a script (let's call it main.pl) printing:

      <html> <head> <title>Redirect</title> <meta http-equiv="refresh" content="0; URL=download.pl?filename=$f +ilename"> </head> </html>
      My download.pl is what I posted on my first post:
      use strict; use warnings; use CGI; my $oCGI = new CGI; my $p_filename= $oCGI->param("filename"); print "Content-Type: application/x-download\n"; print "Content-Disposition: attachment; filename=$p_filename.pdf\n\n"; unlink $p_filename;
      So I'm going to call main.pl -> redirecting to download.pl and now I want to redirect from download.pl to justanotherscript.pl. But when redirecting to justanotherscript.pl I need to get the file download on the same step.

        That's just not possible.

        After sending a HTTP response that gets saved to a file, you cannot send any more data.