The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Help with redirect or alternative solution
Discuss Help with redirect or alternative solution in the PHP Development forum on Dev Shed. Help with redirect or alternative solution PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 6th, 2012, 05:28 PM
|
|
Contributing User
|
|
Join Date: May 2012
Posts: 60
Time spent in forums: 16 h 46 m 3 sec
Reputation Power: 2
|
|
|
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(location: thanks.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?
|

October 6th, 2012, 06:12 PM
|
|
|
|
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.
|

October 6th, 2012, 06:18 PM
|
|
Contributing User
|
|
Join Date: May 2012
Posts: 60
Time spent in forums: 16 h 46 m 3 sec
Reputation Power: 2
|
|
Quote: | 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>.....
|

October 6th, 2012, 06:28 PM
|
|
|
|
Seems like that should work then. Did you check the httpd log for any PHP errors (assuming you have errors turned on)?
|

October 6th, 2012, 06:38 PM
|
|
Contributing User
|
|
Join Date: May 2012
Posts: 60
Time spent in forums: 16 h 46 m 3 sec
Reputation Power: 2
|
|
Quote: | 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
|

October 6th, 2012, 06:47 PM
|
|
Contributing User
|
|
Join Date: May 2012
Posts: 60
Time spent in forums: 16 h 46 m 3 sec
Reputation Power: 2
|
|
|
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
|

October 6th, 2012, 07:11 PM
|
|
|
|
I don't think you can get both. You either download the file or output the page.
|

October 6th, 2012, 07:38 PM
|
|
Contributing User
|
|
Join Date: May 2012
Posts: 60
Time spent in forums: 16 h 46 m 3 sec
Reputation Power: 2
|
|
Quote: | 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?
|

October 6th, 2012, 08:05 PM
|
 |
Lost in code
|
|
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|