[PHP] Redirect after pdf / file download
Hello: I'm trying to emulate a problem i'm trying to solve as follows. 1 - user enters information into a html form and submits 2 - a php script is invoked on the submit and a pdf file is stamped and made available for download 3 - the script finally redirects the user to a thank you html page. i'm having a problem in the redirect to the thank you page. here's the 3 files 1.html htmlbody form action=2.php method=post First Name: input type=text name=firstname / Last Name: input type=text name=lastname / input type=submit / /form /body/html 2.php ?php // some stamping code ... // open the file in a binary mode $name = 2.pdf; fp = fopen($name, 'rb'); // send headers, dump the pdf file and finally redirect header(Content-Type: application/pdf); header(Content-Disposition: attachment; filename=$name); header(Content-Length: . filesize($name)); fpassthru($fp); echo 'script type=text/javascript'; echo 'window.location.href=3.html;'; echo '/script'; ? 3.html htmlbody Thank you for downloading 2.pdf /body/html The submit works fine and the pdf is availble for download however, the redirect does not happen. If i comment the lines //header(Content-Type: application/pdf); //header(Content-Disposition: attachment; filename=$name); //header(Content-Length: . filesize($name)); //fpassthru($fp); then the redirect happens after the submit. i'm testing / running it on fedora core 6, Apache 2.2.5, php 5.2.5 and firefox 1.5 Any help / pointers is appreciated. Thanks. Yashesh Bhatia. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Redirect after pdf / file download
Yashesh Bhatia wrote: Hello: I'm trying to emulate a problem i'm trying to solve as follows. 1 - user enters information into a html form and submits 2 - a php script is invoked on the submit and a pdf file is stamped and made available for download 3 - the script finally redirects the user to a thank you html page. i'm having a problem in the redirect to the thank you page. here's the 3 files 1.html htmlbody form action=2.php method=post First Name: input type=text name=firstname / Last Name: input type=text name=lastname / input type=submit / /form /body/html 2.php ?php // some stamping code ... // open the file in a binary mode $name = 2.pdf; fp = fopen($name, 'rb'); // send headers, dump the pdf file and finally redirect header(Content-Type: application/pdf); header(Content-Disposition: attachment; filename=$name); header(Content-Length: . filesize($name)); fpassthru($fp); echo 'script type=text/javascript'; echo 'window.location.href=3.html;'; echo '/script'; ? 3.html htmlbody Thank you for downloading 2.pdf /body/html The submit works fine and the pdf is availble for download however, the redirect does not happen. If i comment the lines //header(Content-Type: application/pdf); //header(Content-Disposition: attachment; filename=$name); //header(Content-Length: . filesize($name)); //fpassthru($fp); then the redirect happens after the submit. i'm testing / running it on fedora core 6, Apache 2.2.5, php 5.2.5 and firefox 1.5 Any help / pointers is appreciated. Thanks. Yashesh Bhatia. Hi, What you are doing is: header(Content-Type: application/pdf); And after that you try to echo some script. But the browser already thinks that belongs to the PDF and not to a HTML page. What I think should work instead of the script part is just: header('Location: 3.html'); exit; But I'm not sure it works. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Redirect after pdf / file download
Aschwin: Hi i tried -- //echo 'script type=text/javascript'; //echo 'window.location.href=3.html;'; //echo '/script'; header(Location: 3.html); exit; -- but that did not work :(. thanks for the tip. yashesh bhatia Hi, What you are doing is: header(Content-Type: application/pdf); And after that you try to echo some script. But the browser already thinks that belongs to the PDF and not to a HTML page. What I think should work instead of the script part is just: header('Location: 3.html'); exit; But I'm not sure it works. -- Aschwin Wesselius 'What you would like to be done to you, do that to the other' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Redirect after pdf / file download
On Thu, 2008-06-12 at 16:27 +0530, Yashesh Bhatia wrote: Aschwin: Hi i tried -- //echo 'script type=text/javascript'; //echo 'window.location.href=3.html;'; //echo '/script'; header(Location: 3.html); exit; -- but that did not work :(. thanks for the tip. yashesh bhatia What about doing it the other way ... submitting the page to a script that calls on the pdf creation, yet doesnt leave this script - then proceed to redirect when that script (pdf) has been completed? S -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Redirect after pdf / file download
What about doing it the other way ... submitting the page to a script that calls on the pdf creation, yet doesnt leave this script - then proceed to redirect when that script (pdf) has been completed? S steven: the steps u'r suggesting are 1 - submit form (1.html) to script (2.php) 2 - 2.php generates the pdf but does not give it for download 3 - after generating the pdf , 2.php then redirects to 3.html.. so where does the download happen ? in 3.html ? thx. yashesh -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Redirect after pdf / file download
On Thu, Jun 12, 2008 at 7:46 AM, Yashesh Bhatia [EMAIL PROTECTED] wrote: What about doing it the other way ... submitting the page to a script that calls on the pdf creation, yet doesnt leave this script - then proceed to redirect when that script (pdf) has been completed? S steven: the steps u'r suggesting are 1 - submit form (1.html) to script (2.php) 2 - 2.php generates the pdf but does not give it for download 3 - after generating the pdf , 2.php then redirects to 3.html.. so where does the download happen ? in 3.html ? thx. yashesh -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Force the download thru a new window or a frame inside the main window. Then you can redirect the main window to where you need it -- Bastien Cat, the other other white meat
Re: [PHP] Redirect after pdf / file download
You are totally in the wrong way. I would use an a tag and onclick property for opening the PDF in popup relocating the current page HTH Nitsan On 12/06/2008, Yashesh Bhatia [EMAIL PROTECTED] wrote: Hello: I'm trying to emulate a problem i'm trying to solve as follows. 1 - user enters information into a html form and submits 2 - a php script is invoked on the submit and a pdf file is stamped and made available for download 3 - the script finally redirects the user to a thank you html page. i'm having a problem in the redirect to the thank you page. here's the 3 files 1.html htmlbody form action=2.php method=post First Name: input type=text name=firstname / Last Name: input type=text name=lastname / input type=submit / /form /body/html 2.php ?php // some stamping code ... // open the file in a binary mode $name = 2.pdf; fp = fopen($name, 'rb'); // send headers, dump the pdf file and finally redirect header(Content-Type: application/pdf); header(Content-Disposition: attachment; filename=$name); header(Content-Length: . filesize($name)); fpassthru($fp); echo 'script type=text/javascript'; echo 'window.location.href=3.html;'; echo '/script'; ? 3.html htmlbody Thank you for downloading 2.pdf /body/html The submit works fine and the pdf is availble for download however, the redirect does not happen. If i comment the lines //header(Content-Type: application/pdf); //header(Content-Disposition: attachment; filename=$name); //header(Content-Length: . filesize($name)); //fpassthru($fp); then the redirect happens after the submit. i'm testing / running it on fedora core 6, Apache 2.2.5, php 5.2.5 and firefox 1.5 Any help / pointers is appreciated. Thanks. Yashesh Bhatia. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Redirect after pdf / file download
Yashesh Bhatia wrote: What about doing it the other way ... submitting the page to a script that calls on the pdf creation, yet doesnt leave this script - then proceed to redirect when that script (pdf) has been completed? S steven: the steps u'r suggesting are 1 - submit form (1.html) to script (2.php) 2 - 2.php generates the pdf but does not give it for download 3 - after generating the pdf , 2.php then redirects to 3.html.. so where does the download happen ? in 3.html ? thx. yashesh 1. Collect Information from client submit data 2. Process data and generate PDF, write PDF, display error/success message 3. If successful, have a javascript or meta .. redirect to then download PDF generated in step 2. I would do it this way so in case their were any problems generating the PDF, you would have a way to indicate that to the client. Rather then trying to force them to download a broken PDF document. One suggestion to go along with this is that you will need to have a routine that will clean out all the generated PDF's every now and again. -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Redirect after pdf / file download
On Jun 12, 2008, at 8:32 AM, Bastien Koert wrote: On Thu, Jun 12, 2008 at 7:46 AM, Yashesh Bhatia [EMAIL PROTECTED] wrote: What about doing it the other way ... submitting the page to a script that calls on the pdf creation, yet doesnt leave this script - then proceed to redirect when that script (pdf) has been completed? S steven: the steps u'r suggesting are 1 - submit form (1.html) to script (2.php) 2 - 2.php generates the pdf but does not give it for download 3 - after generating the pdf , 2.php then redirects to 3.html.. so where does the download happen ? in 3.html ? thx. yashesh Force the download thru a new window or a frame inside the main window. Then you can redirect the main window to where you need it Frames = Bad! (and that's not an assignment ;) As Richard provided the link (http://www.w3.org/TR/2008/WD-html5-diff-20080610/ ) in a different thread, this comes straight from the article about HTML 5: The following elements are not in HTML 5 because their usage affected usability and accessibility for the end user in a negative way: * frame * frameset * noframes I know we're not in HTML5 yet, but might as well prepare. Sorry to go a bit off topic, but I had to throw that out. =D ~Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php