I have a shoutcast server, and I'm trying to add a piece to my web interface. What I'm looking at doing is removing a line from the playlist. The code works on a test playlist. But when I try it on the real playlist, it fails, because the file is being read by the shoutcast server.
PHP Code:
<?php
$song=$_GET['song'];
$song=$song + 1;
$filename = "/home/draco/shoutcast/transcode/MythMusic.alw"; // File which holds all data
$rowToDelete = $song; // This is line need to be deleted
$arrFp = file( $filename ); // Open the data file as an array
$numLines = count( $arrFp ); // Count the elements in the array
$fp = fopen( $filename, "w" ); // Open the file for writing
for($i=0; $i<$numLines; $i++) // Overwrite the content except the line to be deleted
{
if($i != ($rowToDelete-1) )
fwrite($fp, $arrFp[$i]);
}
fclose( $fp ); // Close the file
?>
I have a bash script (designed with the help of good people from this forum) that can use sed and remove a line from the same file when in use, so I'm assuming that I can do something similar with PHP.
Anyone have a suggestion?
Thanks,
Adam