hey i have a chat program ,,flash and php i was wondering if its possible to clear the chat file periodically ?for an example if 1,000 lines were written can i delete the txt file 's contents ?
im a newbie in php and i dont know where to look ..thanks for any help !
cheers timo
php txt file >>>>>>
Moderator: General Moderators
Though I'm sure someone else here might have a better solution, you could go by the filesize of the file where the chat is stored.
http://us2.php.net/manual/en/function.filesize.php
if(filesize('path/to/file') > 5000)
{
unlink('path/to/file'); // Deletes file
}
But if you delete it, you have to create a clean one
http://us2.php.net/manual/en/function.filesize.php
if(filesize('path/to/file') > 5000)
{
unlink('path/to/file'); // Deletes file
}
But if you delete it, you have to create a clean one
yes sorry for bumping this up but it would be great if someone had a simple snippet ..
i just want to know how to delete the lines in a txt file after a certain ammount of txt has been witten to the file .. unlink isnt working and delete hasnt worked either .. im a newb to php so please explain so i may learn from your replies .. thanks ..
i just want to know how to delete the lines in a txt file after a certain ammount of txt has been witten to the file .. unlink isnt working and delete hasnt worked either .. im a newb to php so please explain so i may learn from your replies .. thanks ..
What is your syntax for the unlink() function?
What I wrote above would delete the file after such and such in bytes.
http://us2.php.net/manual/en/function.filesize.php
http://us2.php.net/manual/en/function.unlink.php
What I wrote above would delete the file after such and such in bytes.
http://us2.php.net/manual/en/function.filesize.php
http://us2.php.net/manual/en/function.unlink.php
Try this and see if that gets you anywhere...
I'm using the fopen with the 'w' mode to truncate the textfile.
Code: Select all
<?php
if (!file_exists('test.txt') or filesize('test.txt') < 200) {
$f = fopen('test.txt', 'a');
fwrite($f, "Line added at filesize: ". filesize('test.txt') . "\n");
fclose($f);
} else {
$f = fopen('test.txt', 'w');
fclose($f);
}
show_source('test.txt');
?>-
seeker2921
- Forum Contributor
- Posts: 120
- Joined: Sat Mar 22, 2003 7:10 pm
- Location: Wiesbaden Germany
- Contact:
I'm woundering if you found this flash chat on Swish-Tutorials.com reason being I found a flash chat on there that use's a txt file and I needed it to be cleared from time to time as well..
I was thinking about changing it to use an MySQL db instead of the flat txt file.. But I have yet to mess with it..
I was thinking about changing it to use an MySQL db instead of the flat txt file.. But I have yet to mess with it..