|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 <html><body> <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 <html><body> 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'/ |
![]() |
| Viewing: Web Development Archives > Mailing Lists > PHP > Redirect after pdf / file download |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|