jdock1 Posted May 20, 2009 Share Posted May 20, 2009 make a dynamic php page downloadable? Meaning, say the browser enters some text into a text field, which that text is a variable, and displays on the next page. When they click the submit button, the variable is displayed on that page. Is it possible to make it kind of like a popup window as if you were downloading something? This may sound pretty stupid. But im doing this kind of as a .htaccess generator, but I cant figure out how to have the user download the page. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/158838-is-it-possible-to/ Share on other sites More sharing options...
MadTechie Posted May 20, 2009 Share Posted May 20, 2009 Yes, just pass the input from the form as normal ie <form action="page2.php" method="POST"> <input name="example" type="text"> <input type="submit" value="press"> </form> <?php echo "you submitted: ".$_POST['example']; ?> once thats done and works correctly you need to force the page to download so change it to <?php header("Cache-Control: no-cache"); header("Expires: -1"); header("Content-disposition: attachment; filename=\"myfile.txt\""); //filename header("Content-type: application/octet-stream"); echo "you submitted: ".$_POST['example']; ?> and that should do it *untested* Link to comment https://forums.phpfreaks.com/topic/158838-is-it-possible-to/#findComment-837780 Share on other sites More sharing options...
jdock1 Posted May 20, 2009 Author Share Posted May 20, 2009 Yes, just pass the input from the form as normal ie <form action="page2.php" method="POST"> <input name="example" type="text"> <input type="submit" value="press"> </form> <?php echo "you submitted: ".$_POST['example']; ?> once thats done and works correctly you need to force the page to download so change it to <?php header("Cache-Control: no-cache"); header("Expires: -1"); header("Content-disposition: attachment; filename=\"myfile.txt\""); //filename header("Content-type: application/octet-stream"); echo "you submitted: ".$_POST['example']; ?> and that should do it *untested* Hmm.. im getting header errors Warning: Cannot modify header information - headers already sent by (output started at /...:2) in /... on line 3 Warning: Cannot modify header information - headers already sent by (output started at /...:2) in /... line 4 Warning: Cannot modify header information - headers already sent by (output started at /...:2) in /... on line 5 Warning: Cannot modify header information - headers already sent by (output started at /...:2) in /... on line 6 you submitted: Any ideas? Link to comment https://forums.phpfreaks.com/topic/158838-is-it-possible-to/#findComment-837862 Share on other sites More sharing options...
Masna Posted May 20, 2009 Share Posted May 20, 2009 Place ob_start() at the top of your script. Scratch that -- you need to place the headers at the very, very top of your script. Link to comment https://forums.phpfreaks.com/topic/158838-is-it-possible-to/#findComment-837863 Share on other sites More sharing options...
jdock1 Posted May 20, 2009 Author Share Posted May 20, 2009 Thanks for the help, actually the problem was that I forgot to edit the example variable to my variable name Link to comment https://forums.phpfreaks.com/topic/158838-is-it-possible-to/#findComment-837878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.