我试图给php文件一个写入JSON文件的权限,但它似乎不起作用。这是我的代码
<?php
$light = $_GET['light'];
if($light == "on") {
$file = fopen("light.json", "w") or die("can't open file");
fwrite($file, '{"light": "on"}');
fclose($file);
}
else if ($light == "off") {
$file = fopen("light.json", "w") or die("can't open file");
fwrite($file, '{"light": "off"}');
fclose($file);
}
chmod(" /home/daffo/public_html/ard/light.json", 0755);
?>
答案 0 :(得分:0)
您必须在第一个斜杠之前删除空格:
chmod("/home/daffo/public_html/ard/light.json", 0755);
答案 1 :(得分:0)
除了显而易见的,在第一次斜线之前删除空格:
chmod("/home/daffo/public_html/ard/light.json", 0755);
您在创建自己的json
时遇到了麻烦。使用内置函数执行此操作:
fwrite($file, json_encode(array("light"=> "off")));