Automated xml playlist problems

I have a script that uploads mp3s to a server and then writes uploaded mp3s to an xml playlist. The problem I have is that the xml playlist is in the wrong format for mp3 player I am using. I have tried to alter the formatting but everytime i change something everything stops working, i really need to get this working and i am starting to loose my sanity! Can anyone please help? I enclose all the neccesary information below, please post if more is needed or if im not making any sense!

The code, at present, for the updating of the xml is as follows:
[php]
/************************************************************

  • List Files/Update XML
    

************************************************************/
$handle=opendir($upload_dir);
$filelist = “”;
$stringdata .= “<?xml version="1.0" encoding="UTF-8" ?>n”;
$stringdata .= “n n”;
while ($file = readdir($handle)) {
if(!is_dir($file) && !is_link($file)) {
$filelist .= "

“.date(“d-m H:i”, filemtime($upload_dir.$file))
.”

“.$file.”[/url]";
if (!$DELETABLE)
$filelist .= “
Not Supported ”;
if ($DELETABLE)
$filelist .= “x[/url]”;
$stringdata .= “n n “.str_replace(”.mp3”,"",$file).“n $url_dir/$upload_dir$filen”;
if ($info == “yes”)
{$stringdata .= " $url_dir$upload_dir$filen";}
if (file_exists(str_replace(".mp3",$ingfilecheck,$file)))
{$stringdata .= " $url_dir$upload_dir".str_replace(".mp3",".jpg",$file).“n”;}
$stringdata .= " ";
}
}
$stringdata .= "nn n
";
$fh = fopen($savefile, ‘w’);
fwrite($fh, $stringdata);
fclose($fh);
[/php]
This script creates the following xml playlist
<?xml version="1.0" encoding="UTF-8" ?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
 <tracklist>

  <track>
   <annotation>01 Intro - Inhale</annotation>
    <location>http://www.blazecheerleaders.co.uk/soundarchitect/files/01 Intro - Inhale.mp3</location>
  </track>
  <track>
   <annotation>talltom</annotation>
    <location>http://www.blazecheerleaders.co.uk/soundarchitect/files/talltom.mp3</location>
  </track>

 </tracklist>

</playlist>

But my mp3 player requires the format of the xml to be as follows…

[code]

<?xml version='1.0' encoding='utf-8'?>

[/code]

Thanks again in advance

Mod Edit: added [php] tags for readability.

What have you tried, and what went wrong with it?

I am really a novice on php, this is the first time i have encountered it, so i just did what seemed logical trying to adapt the lines that start with $stringdata, as that seems to be the function which defines the data to be written to the xml but i get confused as to which part of the code lists the files and which writes the xml. This was my attempt, when i uploaded it to the server with my additions it didnt even display the html, just a blank page.

/************************************************************

  • List Files/Update XML
    

************************************************************/
$handle=opendir($upload_dir);
$filelist = “”;
$stringdata .= “<?xml version="1.0" encoding="UTF-8" ?>n”;
while ($file = readdir($handle)) {
if(!is_dir($file) && !is_link($file)) {
$filelist .= "

“.date(“d-m H:i”, filemtime($upload_dir.$file))
.”

“.$file.”";
if (!$DELETABLE)
$filelist .= “ Not Supported ”;
if ($DELETABLE)
$filelist .= “x”;
$stringdata .= “<song url = “$url_dir/$upload_dir$file” name=”.str_replace(".mp3","",$file).">n";
}
$stringdata .= "nn ";
$fh = fopen($savefile, ‘w’);
fwrite($fh, $stringdata);
fclose($fh);

Sorry code didnt come out formatted…

[code]/************************************************************

  • List Files/Update XML
    

************************************************************/
$handle=opendir($upload_dir);
$filelist = “”;
$stringdata .= “<?xml version="1.0" encoding="UTF-8" ?>n”;
while ($file = readdir($handle)) {
if(!is_dir($file) && !is_link($file)) {
$filelist .= "

“.date(“d-m H:i”, filemtime($upload_dir.$file))
.”

“.$file.”";
if (!$DELETABLE)
$filelist .= “ Not Supported ”;
if ($DELETABLE)
$filelist .= “x”;
$stringdata .= “<song url = “$url_dir/$upload_dir$file” name=”.str_replace(".mp3","",$file).">n";
}
}
$stringdata .= "nn ";
$fh = fopen($savefile, ‘w’);
fwrite($fh, $stringdata);
fclose($fh);[/code][/code]

It looks like you’re on the right track. If you use error_reporting(E_ALL); at the top of your PHP script, do you get any errors when browsing to the page?

[php]/************************************************************

  • List Files/Update XML
    

************************************************************/
$handle=opendir($upload_dir);
$filelist = “”;
$stringdata .= “<?xml version="1.0" encoding="UTF-8" ?>n”;
while ($file = readdir($handle)) {
if(!is_dir($file) && !is_link($file)) {
$filelist .= “

”.date(“d-m H:i”, filemtime($upload_dir.$file))." ".$file."";
if (!$DELETABLE)
$filelist .= “ Not Supported ”;
if ($DELETABLE)
$filelist .= “x”;
$stringdata .= “<song url = “$url_dir/$upload_dir$file” name=”.str_replace(".mp3","",$file).">n";
}
}
$stringdata .= "nn ";
$fh = fopen($savefile, ‘w’);
fwrite($fh, $stringdata);
fclose($fh);[/php]

The page displays fine before i edit it but when i change just that paragraph to what was mentioned above and upload it to my server it just displays blank white. Any idea why this might be?

Ohw, I didn’t change anything your script, except for the formatting (makes it easier on us). Have you tried the error_reporting(E_ALL); option?

Thanks again for your continued help, it is most appreciated. I realise u didnt change anything but i just cant understand why it wouldn’t work. how would I use the error_reporting(E_ALL); option? Does it go in the script? sorry, but as i explained before i am a complete novice in the realms of php.

Try using this:

[php]
error_reporting(E_ALL);

/************************************************************

  • List Files/Update XML
    

************************************************************/
$handle=opendir($upload_dir);
$filelist = “”;
$stringdata .= “<?xml version="1.0" encoding="UTF-8" ?>n”;
while ($file = readdir($handle)) {
if(!is_dir($file) && !is_link($file)) {
$filelist .= “

”.date(“d-m H:i”, filemtime($upload_dir.$file))." ".$file."";
if (!$DELETABLE)
$filelist .= “ Not Supported ”;
if ($DELETABLE)
$filelist .= “x”;
$stringdata .= “<song url = “$url_dir/$upload_dir$file” name=”.str_replace(".mp3","",$file).">n";
}
}
$stringdata .= "nn ";
$fh = fopen($savefile, ‘w’);
fwrite($fh, $stringdata);
fclose($fh);[/php]

as you can see here it still just displays a white page…

http://www.blazecheerleaders.co.uk/Test … tindex.php

but the original still works…

http://www.blazecheerleaders.co.uk/TestXML/index.php

The white page also occurred when i just removed the list files feature i.e. this section of code:

[php]
while ($file = readdir($handle)) {
if(!is_dir($file) && !is_link($file)) {
$filelist .= "

“.date(“d-m H:i”, filemtime($upload_dir.$file))
.”

“.$file.”";
if (!$DELETABLE)
$filelist .= “ Not Supported ”;
if ($DELETABLE)
$filelist .= “x”;
[/php]

here is the rest of the code in the working version, before I changed anything, in case it makes it any clearer as to what the problem could be…

[php]

<?php //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv // You may change maxsize, and allowable upload file types. //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //Maximum file size. You may increase or decrease. $MAX_SIZE = 10000000; //Allowable file ext. names. you may add more extension names. $FILE_EXTS = array('.jpg','.gif','.bmp','.jpeg','.mp3'); //Allow file delete? no, if only allow upload only. $DELETABLE = true; /************************************************************ * Setup variables ************************************************************/ //File you wish to save the playlist to. $savefile = "playlist.xml"; //Allow download of MP3s. $info = "no"; //Directory uploaded files go to. $upload_dir = "files/"; //Image file types checked for in the writting the .xml $imgfilecheck = array(".jpg",".gif",".bmp",".jpeg"); //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv // Do not touch the below if you are not confident. //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ /************************************************************ * Other variables ************************************************************/ $site_name = $_SERVER['HTTP_HOST']; $url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']); $url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; $upload_url = $url_dir."/files/"; $message =""; /************************************************************ * Create Upload Directory ************************************************************/ if (!is_dir("files")) { if (!mkdir($upload_dir)) die ("upload_files directory doesn't exist and creation failed"); if (!chmod($upload_dir,0777)) die ("change permission to 777 failed."); } /************************************************************ * Process User's Request ************************************************************/ if ($_REQUEST[del] && $DELETABLE) { $resource = fopen("log.txt","a"); fwrite($resource,date("Ymd h:i:s")."DELETE - $_SERVER[REMOTE_ADDR]"."$_REQUEST[del]n"); fclose($resource); if (strpos($_REQUEST[del],"/.")>0); //possible hacking else if (strpos($_REQUEST[del],$upload_dir) === false); //possible hacking else if (substr($_REQUEST[del],0,6)==$upload_dir) { unlink($_REQUEST[del]); print "";} } else if ($_FILES['userfile']) { $resource = fopen("log.txt","a"); fwrite($resource,date("Ymd h:i:s")."UPLOAD - $_SERVER[REMOTE_ADDR]" .$_FILES['userfile']['name']." " .$_FILES['userfile']['type']."n"); fclose($resource); $file_type = $_FILES['userfile']['type']; $file_name = $_FILES['userfile']['name']; $file_ext = strtolower(substr($file_name,strrpos($file_name,"."))); //File Size Check if ( $_FILES['userfile']['size'] > $MAX_SIZE) $message = "The file size is over 10MB."; //File Extension Check else if (!in_array($file_ext, $FILE_EXTS)) $message = "Sorry, $file_name($file_type) is not allowed to be uploaded."; else $message = do_upload($upload_dir, $upload_url); print ""; } else if (!$_FILES['userfile']); else $message = "Invalid File Specified."; /************************************************************ * List Files/Update XML ************************************************************/ $handle=opendir($upload_dir); $filelist = ""; $stringdata .= "<?xml version="1.0" encoding="UTF-8" ?>n";

$stringdata .= “n n”;
while ($file = readdir($handle)) {
if(!is_dir($file) && !is_link($file)) {
$filelist .= "

“.date(“d-m H:i”, filemtime($upload_dir.$file))
.”

“.$file.”";
if (!$DELETABLE)
$filelist .= “ Not Supported ”;
if ($DELETABLE)
$filelist .= “x”;
$stringdata .= “n n “.str_replace(”.mp3”,"",$file).“n $url_dir/$upload_dir$filen”;
if ($info == “yes”)
{$stringdata .= " $url_dir$upload_dir$filen";}
if (file_exists(str_replace(".mp3",$ingfilecheck,$file)))
{$stringdata .= " $url_dir$upload_dir".str_replace(".mp3",".jpg",$file).“n”;}
$stringdata .= " ";
}
}
$stringdata .= "nn n
";
$fh = fopen($savefile, ‘w’);
fwrite($fh, $stringdata);
fclose($fh);

function do_upload($upload_dir, $upload_url) {

$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];

$file_name = str_replace("","",$file_name);
$file_name = str_replace("’","",$file_name);
$file_path = $upload_dir.$file_name;

//File Name Check

if ( $file_name =="") {
$message = “Invalid File Name Specified”;
return $message;
}

$result = move_uploaded_file($temp_name, $file_path);
if (!chmod($file_path,0777))
$message = “change permission to 777 failed.”;
else
{$message = ($result)?"$file_name uploaded successfully." :
“Somthing is wrong with uploading a file.”;}

return $message;
}

?>
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service