From 4a65e1af02dff907973d537c728013d202e71f80 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Mon, 23 Jan 2023 20:26:05 +0700 Subject: [PATCH] Fixed broken file_write() function --- common.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/common.php b/common.php index 1460c5f85..3500f37ce 100644 --- a/common.php +++ b/common.php @@ -248,19 +248,19 @@ function file_write($str, $file, $max_size = LOG_MAX_SIZE, $lock = true, $replac rename($file, $new_name); } } - if (file_exists($file) && $dir_created = bb_mkdir(dirname($file))) { - $fp = fopen($file, 'ab+'); - } - if (isset($fp)) { - if ($lock) { - flock($fp, LOCK_EX); + + if (bb_mkdir(dirname($file))) { + if ($fp = fopen($file, 'ab+')) { + if ($lock) { + flock($fp, LOCK_EX); + } + if ($replace_content) { + ftruncate($fp, 0); + fseek($fp, 0, SEEK_SET); + } + $bytes_written = fwrite($fp, $str); + fclose($fp); } - if ($replace_content) { - ftruncate($fp, 0); - fseek($fp, 0, SEEK_SET); - } - $bytes_written = fwrite($fp, $str); - fclose($fp); } return $bytes_written;