Forum Moderators: coopster

Message Too Old, No Replies

Writing to XML File

         

jagger

9:14 pm on Dec 22, 2008 (gmt 0)

10+ Year Member



Hi,

I am working with a drupal module that I had written for me. It is a custom music player. My problem is with the music file that is uploaded. When it is uploaded, it is referenced in the database. It should then write the path to the file in an xml playlist. The problem is one of several. I think it has to do with the concatenation.

url=\"sites/default/files" .$album_song->fmp_song_name. "\" />";

When I upload one file it writes the url as

sites/default/files/./2.mp3

So the problem with this one is an extra ./ which I cannot find in the file.

Secondly when I upload a second song to the playlist it only displays
sites/default/files

Here is the write_xml function.

function write_xml(){
$sql="SELECT fmp_albums.fmp_album_name FROM fmp_albums";
$to_write="<?xml version=\"1.0\" ?>\n\t<songs>";
$result = db_query($sql);
while($dept = db_fetch_object($result)){
$to_write .= "\n\n\t\t<album name=\"".$dept->fmp_album_name."\">";
$song_sql="select fmp_songs.fmp_song_name, fmp_songs.fmp_song_title from fmp_songs where fmp_songs.fmp_album_id=(select fmp_albums.fmp_album_id from fmp_albums where fmp_albums.fmp_album_name='".$dept->fmp_album_name."')";
//$song_sql="select * from fmp_songs,fmp_albums where fmp_songs.fmp_album_id=fmp_albums.fmp_album_id";
$result_song = db_query($song_sql);
while($album_song = db_fetch_object($result_song)) {
$to_write .="\n\t\t\t<song display=\"".$album_song->fmp_song_title."\"
url=\"sites/default/files" .$album_song->fmp_song_name. "\" />";
}
$to_write .= "\n\t\t</album>";
}
$to_write .= "\n\n\t</songs>";
echo $to_write;
$myFile = "modules/music_player/songlist.xml";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $to_write);
fclose($fh);
}

I would be glad to send the module php file to anyone if they need to see more of the code.


Thanks for any help, I am trying to clean up the code that I had written for me.

coopster

1:53 pm on Dec 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, jagger.

So the problem with this one is an extra ./ which I cannot find in the file

./ is current directory, so perhaps it is something already in your database table. I would look at the value in the table that is being selected. If you notice something different in the filepath there, then it is your INSERT statement you need to analyze, you know, when the information was placed in the table, as opposed to it's value on the way back out.