I apologize if this has been asked before but I found no trace of this in the search.
I have a form that a customer fills out that emails data to the site owner and also appends itself to a CSV file on the server. Up to now, the CSV file emails itself to the owner daily. The problem is that the data is always appended to the CSV file and all of the old data is there each day.
Is it possible from PHP to "purge" the CSV file after it's been sent so that it contains only new data? I have limited access to the server so I can't delete the file and have it generate a new one. I need the current file to just empty itself and start over. Does that make sense?
Emptying a CSV file and starting fresh daily
Moderator: General Moderators
-
squatchimo
- Forum Commoner
- Posts: 28
- Joined: Thu Feb 03, 2005 3:36 pm
-
squatchimo
- Forum Commoner
- Posts: 28
- Joined: Thu Feb 03, 2005 3:36 pm
Thanks for the reply feyd. I tried utilizing your idea with the following code:
That snippet runs after the code for mailing the CSV as an attachment. I tested it and the file still contains all original data after each send. What am I missing? Is the code above supposed to do what you said?
EDIT:
I also tried:
Yes, I can write to the file fine. All data submitted goes into the CSV just fine. Any clues? Thanks!
Code: Select all
$fp = fopen('file.csv');
fwrite($fp);
fclose($fp);EDIT:
I also tried:
Code: Select all
fopen('file.csv');
fwrite('file.csv');
fclose('file.csv');- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$fp = fopen('file.csv', 'w');
fclose($fp);-
squatchimo
- Forum Commoner
- Posts: 28
- Joined: Thu Feb 03, 2005 3:36 pm