Languages :: PHP :: Saving the result of a php script into a txt file |
|||
| By: PHP newbee |
Date: 09/10/2002 00:00:00 |
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 | 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 | 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 | 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 |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








