How would I delete the contents of a file, so that it is empty? thanks
open the file in write mode and close it 😉 this will empty the file.
$ft=fopen("/path/to/file","w"); fclose($ft);
if you simply want to delete the file, use unlink() function.
simple enough thanks🙂
I'd unlink it. The write operation will create it, if possible. If not immediately TOUCH it, but you'll still have the same creation issues if that's the case.
Perhaps a fopen, fwrite, fclose is the way to go.
Yeah, I noticed it just recreates the file, but it seems to work fine in my application. What do you mean by TOUCH? thanks
Try...
$file = 'foo.txt'; unlink($file); touch($file);
THe problem with unlinking and touching is that, if the permissions on the directory don't allow you to create files, you're stuck.
You're better off with the first suggestion.
Touch creates a file, and/or updates it's timestamp.