visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: Saving the result of a php script into a txt file


By: PHP newbee U.S.A.  Date: 09/10/2002 00:00:00  English  Points: 300 Status: Answered
Quality : Excellent
The problem: I developed a php script that derives information from a MySQL database, this script formats this information the way I want to and puts it in the browser window (the standard output). Now, what I want is to give the regular browsing user an opportunity to save this formatted information to a txt file to his/her hard drive just clicking on a href link or button. I suppose it is a matter of just changing the output of the php script, but i dunno how to do this.

Please help...
Easy question I think... Take your chance and help me...
By: VGR Date: 09/10/2002 21:26:00 English  Type : Answer
have a look at the ob_* functions

I think you may do whatever you want of the buffer as long as it's not ob_closed
By: VGR Date: 09/10/2002 21:28:00 English  Type : Comment
or better : just do this :

$contents=readfile("yourscript.php");

this way you'll have BOTH the results stored in $contents and the reuslts displayed on screen (that is, your return page).

there are other solutions
By: FiatLink Date: 11/10/2002 11:52:00 English  Type : Comment
Really, the best and fastest way to do this would be to create a txt file and output to it in the same script you use to create the web page.

You can create a file by using fopen and giving it the pointer $file. The "w" below tells PHP to write sequentially from the beginning of the file.

$file = fopen("new.txt", w)

Then, Every time you use "echo" (or whatever you're using) to output your formatted data to the page, use the code below to output it to a text file.

fwrite($file, $formatted_data)

When you've written everything you need, close it with fclose.

fclose($file)

You can then create a link to new.txt on the page that outputs the formatted information. You should delete the file as soon as the user chooses whether or not to download it:

unlink("new.txt")

Do register to be able to answer

EContact
browser fav
page generated in 306.680920 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page