|
Random readdir php to XML
Thanks for viewing my thread. I would like to create a random list of files from a directory. The use of this would be to supply a Flash flv player with a shuffled playlist. Please have a look at this code and maybe you guys can figure out a way to make this php file output a random list of my directory into XML..
The code works great now but Id like it to be random or shuffled on each visit.
THANKS!
<?php
$filter = ".flv";
// path to the directory you want to scan
$directory = "../vids";
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d) {
while($entry=$d->read()) {
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false)) {
$items[] = $entry;
}
}
$d->close();
sort($items);
}
// we'll first add an xml header and the opening tags ..
header("content-type:text/xml;charset=utf-8");
echo "<ratings>\n";
// .. then we loop through the mysql array ..
for($i=0; $i<sizeof($items); $i++) {
echo "<video file=\"$dir$items[$i]\" >\n";
echo " <title>".str_replace(".flv","",$items[$i])."</title>\n";
echo " <runtime>auto</runtime>\n";
echo " </video>\n";
}
echo "</ratings>\n";
?>
THE OUTPUT LOOKS LIKE THIS:
<ratings>
<video file="video1.flv">
<title>video1</title>
<runtime>auto</runtime>
</video>
<video file="video2.flv">
<title>video2</title>
<runtime>auto</runtime>
</video>
<video file="video3.flv">
<title>video3</title>
<runtime>auto</runtime>
</video>
|