Jump to content

fopen, fwrite and fclose help with a text file


victorianrider

Recommended Posts

Hey guys,

 

 

I have a script that is run once a week to fetch some user info for a large number of accounts.

The code I have now writes the info correctly, but I was wondering if there was an easy way to have the accountdata.txt file completely wiped before new updated info is written to it, as opposed to deleting it manually every week.

        $FileName = "accountdata.txt";
$f=fopen($FileName,"a+");
fwrite($f, $UserKey[$i]." ".$SigKey[$i]."\n");
$f=fclose;

 

I could in theory just open the file and delete everything in it manually, save it and then run this script, but I'm always looking for more ways to make things efficient, and come a time when it's run more than once a week it'd be nice to have all that automated.

 

So in summary, I need it to delete all data (if any) from the accountdata.txt file before it writes anything to it.

 

Thanks.

If you want this all in one script, you could add a little code that finds the day of the week based on date, so if you want this to be done let's say on Sunday only, something like:

 


if (date('N') == 7)
  unlink($FileName);

If you want this all in one script, you could add a little code that finds the day of the week based on date, so if you want this to be done let's say on Sunday only, something like:

 


if (date('N') == 7)
  unlink($FileName);

 

Thankyou very much :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.