xml php website stuff automation?

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?

it was suggested to me that i shuffle the array, but seeing as i dont knowvery much PHP i cannot figure out how to shuffle the array and make it work, can someone please help me?

<?php

$defaultExtension = 'mp3'; // it can be changed
$filetype = isset($_GET['type'])?$_GET['type']:$defa…
$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,'.')+… == $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