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

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.

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

    That's just not possible.

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

      That's exactly what I don't understand. What make the difference, that my way won't work compared to what you said "reverse the steps you're doing"?

      I got 4 scripts. Script 1 showing a form. If sending the form, script 2 is working with the data printing meta-redirect tag to script 3. Why I can't say download and redirect to script 4?

      If I would leave script 3 and call script 4 with one parameter more, nothing will be shown, because I had to use the content-type in script 4 which won't show my html. - Expected it would show something, would I be able to click links in this case?


      Edit: What about using javascript opening a new tab calling my download script there. Should be possible?

        A file download is not interpreted as HTML.

        You can only output one set of headers. If you output the headers for the download first, you will never be able to send the user to another page to send more data to the user.

        I suggest you learn HTTP and how the different content types and headers work.