Reputation: 996
I'm working on enabling and disabling a value with PHP that's stored with a config.json file I have for my modules. The format of the config file is
{
"details": {
"name": "Doxramos Core Login",
"root": "index.inc",
"language": "en_US",
"ident": "dxcl",
"version": "1.0",
"author" : "Doxramos Development",
"date" : "5/31/2016",
"module_url" : "allthingscode.net",
"author_url" : "allthingscode.net",
"core": true,
"version_tested": 1.0
},
"options": {
"location": "right_well",
"enabled": true
}
}
For my PHP Function I have it run
function ToggleModule($status, $configFile) {
$string = file_get_contents($configFile);
$json_a = json_decode($string, true);
$json_a['options']['enabled'] = $status;
}
So with this all the parameters are passed successfully; the $json_a['options']['enabled']
value is controlled by the post variable, but I don't know how to get the file to save afterwards.
Upvotes: 1
Views: 189
Reputation: 1712
Try this. It should help you. This will create new.json file
$fp = fopen('new.json', 'w');
fwrite($fp, json_encode($json_a));
fclose($fp);
Upvotes: 2