So I want to create an image that starts in a state based on a PHP function, and when clicked changes state.
I have not found any way to get the return value from a function in PHP to HTML. If I can do this, my problem is solved.
<?php
if(isset($_GET['button1'])){toggle();}
function toggle()
{
$filename = "brightness";
$otherDirectory="/sys/class/leds/led0/";
$f = fopen($otherDirectory . $filename,"r");
$value = fgets($f);
$newvalue = 1;
fclose($f);
if ((int)$value == 1) {
$newvalue = 0;
}
if ((int)$value == 0) {
$newvalue = 1;
}
$f = fopen($otherDirectory . $filename,"w+");
fwrite($f, $newvalue);
fclose($f);
}
function getLampState(){
$filename = "brightness";
$otherDirectory="/sys/class/leds/led0/";
$f = fopen($otherDirectory . $filename,"r");
$value = fgets($f);
return $value;
}
?>
<html><body>
<img src="lightbulb_1.png" onClick='location.href="?button1"'/>
</body></html>
Don't mind the toggle() function, I'm done with that. I have 2 files (lightbulb_1 and lightbulb_0). If getLampState() returns 1, I want to show lightbulb_1, vice versa.
Any advice?