Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Perl CGI download file and redirect

by Yaerox (Scribe)
on Nov 17, 2014 at 14:25 UTC ( [id://1107416]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1107416]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-25 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found