i need help with php, xml, stuff?

Twilight

New member
right now i have a php script(Below)hat will take the songs in a folder and create an xml playlist which is then sent to the music player on my webpage. the problem is that the xml playlist it generates is not random, so the same songs always come up in the same order. is there an easy way to edit the script to generate a random playlist from the folder of songs? if not can someone direct me to a resource that will teach me what i need to know to either change the script or write a new one?

<?php

$defaultExtension = 'mp3'; // it can be changed
$filetype = isset($_GET['type'])?$_GET['type']:$defaultExtension;
$dir = $_GET['dir'];

$rootDir = ''; //don't change zis :)
$files = array();

if(is_dir($dir))
{

$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
if($filename != '.' and $filename != '..' and is_dir($dir.'/'.$filename))
$dirs[] = $filename;
}


sort($dirs);

$rootDir = $dir;

foreach($dirs as $dir){
$d2h = opendir($rootDir.'/'.$dir);
$files[$dir] = array();

while (false !== ($filename = readdir($d2h))) {
if($filename != '.' and $filename != '..' and !is_dir($rootDir.'/'.$dir.'/'.$filename)
and substr($filename,strrpos($filename,'.')+1) == $filetype)
array_push($files[$dir],$filename);
}
}

}

echo '<?xml version="1.0" encoding="utf-8"?>';
echo '
<playlist>';
foreach($files as $folder => $list_of_files){
if(sizeof($list_of_files)>0){
echo '
<folder name="'.$folder.'">';
foreach($list_of_files as $file){
echo '
<file path="'.$rootDir.'/'.$folder.'/'.$file.'" />';
}
echo '
</folder>';
}
}
echo '
</playlist>';

?>
 
Back
Top