Create and send text file

Reply

Join Date: Mar 2007
Posts: 2
Reputation: pcs123 is an unknown quantity at this point 
Solved Threads: 0
pcs123 pcs123 is offline Offline
Newbie Poster

Create and send text file

 
0
  #1
Mar 18th, 2007
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
  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?
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 2
Reputation: pcs123 is an unknown quantity at this point 
Solved Threads: 0
pcs123 pcs123 is offline Offline
Newbie Poster

Re: Create and send text file

 
1
  #2
Mar 18th, 2007
Sorry for disturbing. I should better read the manual. It is just simple:
  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. ?>
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1
Reputation: capivarachess is an unknown quantity at this point 
Solved Threads: 0
capivarachess capivarachess is offline Offline
Newbie Poster

Re: Create and send text file

 
0
  #3
Aug 6th, 2008
Hi!

You did not disturbed here.

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

Thanks,

Chess Patzer.

Originally Posted by pcs123 View Post
Sorry for disturbing. I should better read the manual. It is just simple:
  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. ?>
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 1
Reputation: raheelfarooq is an unknown quantity at this point 
Solved Threads: 0
raheelfarooq raheelfarooq is offline Offline
Newbie Poster

great job!

 
0
  #4
Nov 11th, 2009
Thanks buddy!

Originally Posted by pcs123 View Post
Sorry for disturbing. I should better read the manual. It is just simple:
  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. ?>
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,085
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster
 
0
  #5
Nov 11th, 2009
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.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 6554 | Replies: 4
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC