I need to remove the contents of a file, but not remove the file entirely. Can this be done with php? I assume yes, but how?
Thanks in advance! 🆒
Are you trying to delete contents of a file? Or part of a record in a database?
the contents of a text file
For what I know, and I'm still pretty new at this, but PHP is used for database interaction. Is this just a text file?
yep, i'm sure it can.. i can use unlink, but then it deletes the entire file.
<?php if ($file = @fopen("path/to/file","w")) { // Replace contents with an empty string fputs($file, ""); fclose($file); } else { echo "Failed to open file for writing."); } ?>
Cheers!! thank you much!
Originally posted by satch Cheers!! thank you much!
You're welcome. 🙂