Downloading a text file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bdeonline
Forum Commoner
Posts: 42
Joined: Sun Jul 18, 2004 10:45 am

Downloading a text file

Post by bdeonline »

Hi all,
I'm needing a text file to download to the client that is generated as a php file. Thing is the browser wants to open it and when you use right click save as it wants to add the .php ending to it. I need this supper simple for a user to use is there any type of header I can use that will make this download as a simple .txt.

Or can I some how add this to a attachment and send it via email? All the examples I've seen are for attaching binary information and not simple text.
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post by php_wiz_kid »

You can use the Content-Disposition header to supply a recommended filename and force the browser to display the save dialog.

Code: Select all

header('Content-Disposition: attachment; filename="downloaded.txt"');
Post Reply