944,052 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 20621
  • PHP RSS
Mar 18th, 2007
0

Create and send text file

Expand Post »
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
PHP Syntax (Toggle Plain Text)
  1. <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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pcs123 is offline Offline
2 posts
since Mar 2007
Mar 18th, 2007
1

Re: Create and send text file

Sorry for disturbing. I should better read the manual. It is just simple:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. header('Content-type: application/txt');
  3. header('Content-Disposition: attachment; filename="day.txt"');
  4. echo date("l");
  5. echo "\r\n";
  6. ?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pcs123 is offline Offline
2 posts
since Mar 2007
Aug 6th, 2008
0

Re: Create and send text file

Hi!

You did not disturbed here.

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

Thanks,

Chess Patzer.

Click to Expand / Collapse  Quote originally posted by pcs123 ...
Sorry for disturbing. I should better read the manual. It is just simple:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. header('Content-type: application/txt');
  3. header('Content-Disposition: attachment; filename="day.txt"');
  4. echo date("l");
  5. echo "\r\n";
  6. ?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
capivarachess is offline Offline
1 posts
since Aug 2008
Nov 11th, 2009
0

great job!

Thanks buddy!

Click to Expand / Collapse  Quote originally posted by pcs123 ...
Sorry for disturbing. I should better read the manual. It is just simple:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. header('Content-type: application/txt');
  3. header('Content-Disposition: attachment; filename="day.txt"');
  4. echo date("l");
  5. echo "\r\n";
  6. ?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
raheelfarooq is offline Offline
1 posts
since Nov 2009
Nov 11th, 2009
0
Re: Create and send text file
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.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how to write regular expression in PHP?
Next Thread in PHP Forum Timeline: DATA TYPE in phpmyadmin





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC