File: C:/xampp/htdocs/myapi/postTestEsc.php
<?php
// Get the JSON data sent from the client
$json = file_get_contents('php://input');
// Decode JSON to PHP array
$data = json_decode($json, true);
// Process the data
if ($data !== null) {
// Access the JSON values
$dStr = $data['prex'];
$patch1 = $data['patch1']; // json_decode already unescapes \n, \t, \" sequences
$myFile ="../FograCT1/upload/".$dStr;
$fvcc = fopen($myFile, 'w') or die("can't open file");
fwrite($fvcc, $patch1);
fclose($fvcc);
echo json_encode(array('message' => 'Data received and processed successfully'));
} else {
echo json_encode(array('message' => 'Invalid JSON data'));
}
?>