I have this piece of code:
$file = fopen($path, 'r+'); flock($file, LOCK_EX); // reading the file into an array and doing some stuff to it for ($i=0; $i<count($array); $i++) { fwrite($file, $array[$i]); } flock($file, LOCK_UN); fclose($file);
Basically what I want to do: open the file> lock it> read> do something> clear the file > write to the file> unlock it> close it.
The problem is the clearing part. I know I can do this with fopen($file, 'w+') , but then reading will be a problem. Maybe I can somehow change the mode ?
Any help would be appreciated Paul
source share