0
到目前为止,我已经设置了窗体和服务来读取应该对json文件进行编辑的php文件。我目前的PHP文件看起来像这样。如何使用Angular 4中的表单通过PHP更新json文件?
if(empty($errors))
{
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$name = $request->name;
$designation = $request->designation;
$current_data = file_get_contents('currency.json');
$array_data = json_decode($current_data, true);
$extra = array(
'name' => $name,
'designation' => $designation
);
$array_data[] = $extra;
$final_data = json_encode($array_data);
if(file_put_contents('currency.json', $final_data))
{
$message = "<label class='text-success'>File Appended Success fully</p>";
}
}
else
{
$error = 'JSON File not exits';
} `enter code here`
I will appreciate any effort for help.
hello @Kiril。你能否提供更多细节? –
这里有什么问题?为什么使用php://输入来读取通过表单提交的数据? –