'Invalid JSON data provided.', 'json_error' => json_last_error_msg() ], JSON_UNESCAPED_UNICODE); // 기존 JSON 파일 삭제 if (file_exists($jsonFilePath)) { unlink($jsonFilePath); } exit; } // 만약 모든 데이터가 빈 값이라면, JSON 파일을 삭제하고 DB 업데이트 시 빈 값으로 처리 if (isAllEmpty($realiList_jsondata)) { if (file_exists($jsonFilePath)) { unlink($jsonFilePath); } echo json_encode([ 'num' => $safeGroupCode, 'message' => 'JSON data is empty. JSON file deleted and database updated.', 'realiList_jsondata' => $realiList_jsondata ], JSON_UNESCAPED_UNICODE); exit; } // JSON 데이터를 파일에 저장 $saveResult = file_put_contents($jsonFilePath, json_encode($realiList_jsondata, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); if ($saveResult === false) { echo json_encode(['error' => 'Failed to write JSON file.'], JSON_UNESCAPED_UNICODE); exit; } } else { echo json_encode(['error' => 'No realiList data provided.'], JSON_UNESCAPED_UNICODE); exit; } $data = [ 'num' => $safeGroupCode, 'json_file' => $jsonFilePath, 'realiList_jsondata' => $realiList_jsondata, 'message' => 'JSON data saved to file and database updated successfully.' ]; echo json_encode($data, JSON_UNESCAPED_UNICODE); ?>