[SOLVED] .txt flush

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

.txt flush

Post by Joe »

Is there any function or method in PHP to flush the contents of a .txt file on your server. I have been doing some practice with coding and I am sort of confused at this part. Any help appreciated?
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

when you say flush, just what exactly do you want to do? if you are talking about clearing a file before you write to it look at the switches you can use with fopen() "w" is probably the one you want. If this is not what you are trying to do, give us a little more detail.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

There's fflush: http://us2.php.net/manual/en/function.fflush.php
but that flushes the data buffer.

If your trying to clear a file? That is delete the data and not the file then ...

1. Creating a empty temporary file.
2. Renaming that temp file to one you want cleared.

This is an atomic operation (on linux) so anyone reading the old file can finish.

Like Wayne said a little more detail might help?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Buddha443556 wrote:There's fflush: http://us2.php.net/manual/en/function.fflush.php
but that flushes the data buffer.

If your trying to clear a file? That is delete the data and not the file then ...

1. Creating a empty temporary file.
2. Renaming that temp file to one you want cleared.

This is an atomic operation (on linux) so anyone reading the old file can finish.

Like Wayne said a little more detail might help?
or just:

Code: Select all

<?php

fclose(fopen('filename','wb'));

?>
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Excellent. All works perfect now. I used the "w" switch in fopen which done the trick. Sorry I never explained to well but at least you guys helped out!

Regards



Joe 8)
Post Reply