diff --git a/libs/keyLib.php b/libs/keyLib.php index a321677..113db0e 100755 --- a/libs/keyLib.php +++ b/libs/keyLib.php @@ -109,7 +109,7 @@ { if (!isset($fileName) || !isset($keyData)) return false; - $handle = fopen($fileName, 'w+'); + $handle = fopen($fileName, 'c'); if ($handle == null) return false; // debug code @@ -122,7 +122,9 @@ //use exclusive lock for writing flock($handle, LOCK_EX); + ftruncate($handle, 0); $res = fwrite($handle, $data); + fflush($handle); flock($handle, LOCK_UN); // debug Code //if ($res == false) diff --git a/libs/loggingLib.php b/libs/loggingLib.php index da5f4af..4a4bf7f 100755 --- a/libs/loggingLib.php +++ b/libs/loggingLib.php @@ -200,7 +200,7 @@ */ function WriteLogFile($fileName, &$questionData, &$tutorData, &$commentData) { - $handle = fopen($fileName, 'w'); + $handle = fopen($fileName, 'c'); if (!$handle) return false; // write disclaimer and question data block identifier @@ -234,7 +234,9 @@ // write the generated data to the file and close it // use exclusive lock flock($handle, LOCK_EX); + ftruncate($handle, 0); fwrite($handle, $fileData); + fflush($handle); flock($handle, LOCK_UN); fclose($handle); return true;