db없이 텍스트 파일로 데이터 저장하고있음

파일 모드 한개로 통일할라니까 자꾸 꼬여서 빡쳐버림...

그냥 읽기 쓰기 나눠서 해버렸음 ㅎㅎ


$app->get("/bbs/write",function($req,$res){

    

    if($_POST["email"]){

        include_once "application/public/data/contentClass.php";

          $fileName = "application/public/data/board.txt";  


        if(!file_exists($fileName)){

        $file = fopen($fileName, "c");              

            $contents = new Contents();

            $contents->contents = array(new Content($_POST["title"],$_POST["des"],$_POST["email"],$_POST["password"]));

            fwrite($file,json_encode($contents));

            fclose($file); 

        }else{

            $rf = fopen($fileName, "r");  

            $json = fread($rf,filesize($fileName));

            fclose($rf);

            

            $wf = fopen($fileName, "w");

            $contents = json_decode($json);

            array_push($contents->contents ,new Content($_POST["title"],$_POST["des"],$_POST["email"],$_POST["password"]));

            fwrite($wf,json_encode($contents));

         

            fclose($wf);

        }

        header("Location: http://localhost/bbs/board");

        die();

    }else{

        $res->render("bbs/write",$data);

    }

});