Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.