File access
Posted: Thu Mar 06, 2014 2:06 am
I guess this is a linux question but it's on a Pi so here is my question...
I have a script file located in /bin with a selection of streaming radio stations where all but one is remmed out "#"
This file is launched at boot time and plays the selected stream link.
I've installed mplayer and lamp on my Pi starting from "2014-01-07-wheezy-raspbian"
I have some PHP code that allows me to select what station i want to stream and this should modify my bash script file by changing where to remove the "#" in front of the streaming link.
My code is using file() but for some reason I get the die side of it and am unable to modify the file in /bin
To my understanding, it is probably related to the user rights to that file but as much as I've searched, I am finding nothing I can understand.
Here is the code in charge of modifying the script...
I have a script file located in /bin with a selection of streaming radio stations where all but one is remmed out "#"
This file is launched at boot time and plays the selected stream link.
I've installed mplayer and lamp on my Pi starting from "2014-01-07-wheezy-raspbian"
I have some PHP code that allows me to select what station i want to stream and this should modify my bash script file by changing where to remove the "#" in front of the streaming link.
My code is using file() but for some reason I get the die side of it and am unable to modify the file in /bin
To my understanding, it is probably related to the user rights to that file but as much as I've searched, I am finding nothing I can understand.
Here is the code in charge of modifying the script...
Code: Select all
<?php
$filename = "/bin/play-radio";
$file_content = file($filename);
$x = count($file_content);
$fp = fopen($filename, "w+") || die("Cannot open".$filename);
$y = 0;
$c = 1;
while($y < $x)
{
if (substr($file_content[$y],0,6) == '#title'){
if ($_POST["rd"] == $c AND substr($file_content[$y+1],0,1) == '#'){
$file_content[$y+1] = substr($file_content[$y+1],1,strlen($$file_content[$y+1])-1);
fwrite($fp, $file_content[$y+1]);
$y++;
}
else if ($_POST["sel"] == $c AND substr($file_content[$y+1],0,1) != '#'){
$file_content[$y+1] = '#'.$file_content[$y+1];
fwrite($fp, $file_content[$y+1]);
$y++;
}
else {
fwrite($fp, $file_content[$y]);
}
$c++;
}
else {
fwrite($fp, $file_content[$y]);
}
$y++;
}
fclose($fp);
/**header('Location: index.php');**/
?>