I use this code for read the directory of my photo in the rotator:
<?
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".jpg";
// path to the directory you want to scan
$directory = "public/photo";
// 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);
}
// third, the playlist is built in an xspf format
// we'll first add an xml header and the opening tags ..
header("content-type:text/xml;charset=utf-8");
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Sample PHP Generated Playlist</title>\n";
echo " <info>http://www.jeroenwijering.com/</info>\n";
echo " <trackList>\n";
// .. then we loop through the mysql array ..
for($i=0; $i<sizeof($items); $i++) {
echo " <track>\n";
echo " <title>".$items[$i]."</title>\n";
echo " <location>xxx</location>\n";
echo " </track>\n";
}
// .. and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
?>
this code work correctly, but does not read files in the sub folders...
My folder photo($directory = "public/photo";), contains other 30 folders, how can read the files in subfolders for them to the playlist?
<?php // *** requires PHP5 ***// search for jpg files
$filter = ".jpg"; // path to the directory you want to scan$directory = './'; $it = new RecursiveDirectoryIterator("$directory");
foreach(
new RecursiveIteratorIterator($it) as $file){
if (!((strpos(strtolower($file), $filter)) === false))
{
$items[] = preg_replace("#\\\#", "/", $file);
}
}
sort($items); header("content-type:text/xml;charset=utf-8"); echo "<?xml version='1.0' encoding='UTF-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Sample PHP Generated Playlist</title>\n";
echo " <info>http://www.jeroenwijering.com/</info>\n";
echo " <trackList>\n";
foreach($items as $item)
{
$title_array = explode('/', $item);
$title = substr(end($title_array), 0, (strlen(end($title_array)) - 4));
echo " <track>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $item . "</location>\n";
echo " </track>\n";
}
echo " </trackList>\n";
echo "</playlist>\n";
?>