Created
December 26, 2018 09:25
-
-
Save alegut/00944b9b3e7ee897cbdcb696e6a44941 to your computer and use it in GitHub Desktop.
Send JSON data from POST request to txt file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("Content-Type: application/json; charset=UTF-8"); | |
$data = json_decode(file_get_contents('php://input'), true); | |
//print_r($data); | |
foreach($data as $key => $value) | |
{ | |
$str.=$key.":".$value."\n"; | |
} | |
$file = 'people.txt'; | |
// Open the file to get existing content | |
$current = file_get_contents($file); | |
// Append a new person to the file | |
$current .= "new Record: \n".$str; | |
// Write the contents back to the file | |
file_put_contents($file, $current); | |
echo $str; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment