#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    85
    Rep Power
    3

    Help with redirect or alternative solution


    I have this form a user fills out.
    The data is sent to a script that processes the data and creates a file stored on the server.

    The page redirect to a thank you message that is being shown and the file automatically be server.

    As it is now the proccessing file redirects with
    PHP Code:
    header(locationthanks.php); 
    The thanks.php file is shown as long as I dont have the file served to the user - using this code

    PHP Code:
    <?php

    header
    ('Content-type: application/powerpoint');

    header('Content-Disposition: attachment; filename="downloaded.pptx"');

    readfile('presentation.pptx');

    ?>
    When I add this code to thanks.php the page will not be displayed.
    I tried to use the header redirect method in thanks.php to redirect to a file called download.php but that will not work since the function will create a new header and bypass the html content of thanks.php

    I guess the reason why thanks.php is not shown when above code is present is because a new header is created and the html content therefor bypassed?

    What should I do?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,617
    Rep Power
    595
    What precedes the headers? There can be nothing, not even whitespace, before the headers or they will be ignored.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    85
    Rep Power
    3
    Originally Posted by gw1500se
    What precedes the headers? There can be nothing, not even whitespace, before the headers or they will be ignored.
    right now nothing

    PHP Code:
    <?php
    header
    ('Content-type: application/powerpoint');
    header('Content-Disposition: attachment; filename="downloaded.pptx"');
    readfile('02presentation.pptx');
    ?>


    <!DOCTYPE html>
    <html>
    <head>.....
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,617
    Rep Power
    595
    Seems like that should work then. Did you check the httpd log for any PHP errors (assuming you have errors turned on)?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    85
    Rep Power
    3
    Originally Posted by gw1500se
    Seems like that should work then. Did you check the httpd log for any PHP errors (assuming you have errors turned on)?
    there is no relating errors
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    85
    Rep Power
    3
    Well, as I mention the file is being served for download when thanks.php is loaded. It is the html content that is not being displayed
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,617
    Rep Power
    595
    I don't think you can get both. You either download the file or output the page.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    85
    Rep Power
    3
    Originally Posted by gw1500se
    I don't think you can get both. You either download the file or output the page.
    Then how would I alternativly do this?
  16. #9
  17. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    On your thanks.php use JavaScript to redirect the user to download.php.

    You can't serve a download and output HTML in the same request.

    You can send a Location header and output HTML in the same request, but most browsers will not show the HTML.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo