how do i shuffle the array? php?

Twilight

New member
the code(Below) takes files and makes an xml playlist of the files to be used by a web player. the problem is that the playlist starts on the same song and has the same order.

jacovkss said i can just shuffle the array, but i dont know php or any programming languages for that matter. so can someone please just edit the code for me?

<?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