954,591 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Create and send text file

I wonder if it is possible to send text file which is just at this moment prepared and it would be best if the file coud be send without creating on disc.
For example I would like to have on my web

<a href="day.php">this day</a>


and when you click on this link day.php starts sending file day.txt which wil contain only one line with "monday" or "tuesday" etc. So browser will ask where you want to save this file. Is it possible to even send file day.txt without creating it on server?

pcs123
Newbie Poster
2 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

Sorry for disturbing. I should better read the manual. It is just simple:

<?php
header('Content-type: application/txt');
header('Content-Disposition: attachment; filename="day.txt"');
echo date("l");
echo "\r\n";
?>
pcs123
Newbie Poster
2 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

Hi!

You did not disturbed here.

It was very usefull for me and solved mine problem here.

Thanks,

Chess Patzer.

Sorry for disturbing. I should better read the manual. It is just simple:

<?php
header('Content-type: application/txt');
header('Content-Disposition: attachment; filename="day.txt"');
echo date("l");
echo "\r\n";
?>
capivarachess
Newbie Poster
1 post since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

Thanks buddy!

Sorry for disturbing. I should better read the manual. It is just simple:

<?php
header('Content-type: application/txt');
header('Content-Disposition: attachment; filename="day.txt"');
echo date("l");
echo "\r\n";
?>
raheelfarooq
Newbie Poster
1 post since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

There manual page on the readfile() function has some really good information and examples on sending a HTTP response with different headers. For example, if you want to support resuming downloads.

http://php.net/manual/en/function.readfile.php

A good thing to note for having PHP send your files is that you should use flush() if you want to start sending immediately. Otherwise PHP will buffer the output.
http://www.php.net/manual/en/function.flush.php

This is useful if you're sending a large txt download.

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You