View Full Version : Empty a file?
duniyadnd
01-13-2003, 06:23 PM
Just in case no one can get the solution to the post I posted earlier, does anyone know a way of "emptying" a file? Not just replace every character with " ", but literally emptying the whole file.
Thanks
Duniyadnd
i dont know every php function so there might be a better way to do this. you could unlink/delete the file then create a new file with that same name but not put anything in it.
duniyadnd
01-14-2003, 01:40 AM
Yeah, I thought of that, I just don't want the chance that someone else is logging onto the page and finds an empty file, or a non existant file. I hope flock() works in this case.
Thanks
Duniyadnd
whisk
01-14-2003, 04:14 AM
read up on ftruncate()
anywho.. I can't help you out any further since I will be departing these childishly moderated forums.. hope that function helps.. if it doesn't try http://www.phphelp.com I'm there often. :D
all the best buddy.
firepages
01-14-2003, 02:04 PM
approacheth a childlike moderator who knows not what he is party to but anyway...
just fopen() the file for writing, that will empty the file for you...
<?
$file='/path/to/file.txt';
fclose(fopen($file,'w'));
?>
duniyadnd
01-14-2003, 05:10 PM
coolio, that worked, now does anyone know why that worked??
I got to say, i came up with funky algorithms just to try to get this working.. :cool:
Thanks
Duniyadnd :thumbsup:
bored
01-18-2003, 06:40 AM
Quoted from php.net:
'w' - Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
Truncate to zero length means empty.
Algorithms for what? That is insane.
duniyadnd
01-18-2003, 03:12 PM
Algorithms for what? That is insane.
- Hence the funkiness.. :D
bored
01-20-2003, 01:21 AM
I don't understand. Maybe I'm one of the few that actually reads the manual.
firepages
01-20-2003, 01:28 AM
question asked and answered - a post-mortem is not required so closing ;)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.