function add_to_playlist ($songName, $artistName, $songFile) { $title = $songName; $creator = $artistName; $location = "../uploads/misc/".$songFile; $somecontent = '' . "\n\t" . '' . "\n\t\t\r\t\t\t" . ''.$title.'' . "\n\t\t\t" . ''.$creator.'' . "\n\t\t\t" . ''.$location.'' . "\n\t\t" . '' . "\n\n"; $playlist = '../mp3/playlist.xml'; $inhandle = fopen($playlist, "rb"); $contents = fread($inhandle, filesize($playlist)); fclose($inhandle); $exploded = explode("\n", $contents); // Let's make sure the file exists and is writable first. if (is_writable($playlist)) { // In our example we're opening $inhandle in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($playlist, 'wt')) { echo "Cannot open file ($playlist)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($playlist)"; exit; } for ($i = 9; $i < 1000; $i++) { fwrite($handle, $exploded[$i]); } fclose($handle); } else { echo "The file $playlist is not writable"; } }