at start, I come with a JSON array, like this one :
[
{
"login":"Admin",
"admin":true,
"root":true
},
{
"login":"PMO",
"admin":true,
"root":false
}
]
I want to overwrite the content of this JSON array by another, which is into the variable $scope.users I first send it to a PHP file from a controller :
$http.post('php/users/deleteUser.php', $scope.users);
which overwrites the old json file
<?php
$data = file_get_contents("php://input");
file_put_contents('../users/users.json', $data);
?>
But when I open the file users.json, the content is malformed :
0%5Blogin%5D=Admin&0%5Badmin%5D=true&0%5Broot%5D=true&0%5B%24%24hashKey%5D=01R&1%5Blogin%5D=PMO.....
I don't manage to get where it comes from. I've tried all possible combinations with JSON.parse, JSON.stringify, json_encode, json_decode. I also tried to write the $http request like this :
$http({
method:"POST",
url:'php/users/deleteUser.php',
data:$scope.users,
headers: {'Content-Type': 'application/json'}
});
But nothing changes the result. Any idea ?
php://input
is RAW input. You'd have to urldecode() it first to conver the[]{}"
back to normal characters. Normally you should let PHP do it for you, which means sending overdata=$json_string
and the getting the decoded string from$_POST['data']
– Marc B Jul 8 '14 at 22:36{"login":"Admin",....}
– Marc B Jul 8 '14 at 22:47