Page 1 of 1

.txt flush

Posted: Tue Jun 15, 2004 8:20 am
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?

Posted: Tue Jun 15, 2004 10:07 am
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.

Posted: Tue Jun 15, 2004 10:20 am
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?

Posted: Tue Jun 15, 2004 2:53 pm
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'));

?>

Posted: Tue Jun 15, 2004 6:31 pm
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)