Jump to content

Is it possible to...


jdock1

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.