Good morning! Below is a script that I have been working on that reads a directory of mp3 files and creates an XML of the data it collected. I have a basic understanding of PHP and XML. My problem is that I would like to be able to sort the data. I would like the XML to start with the LATEST uploaded file first. So, in other words....if a new MP3 is uploaded to the directory....that one is the first shown. What do you recommend I do to the below code to make this happen?
Thank you in advance.
<?php
header("Content-Type: text/xml");
// include getID3() library (can be in a different directory if full path is specified)
require_once('/httpd/customers/virtual/mydomain.com/htdocs/tag/getid3/getid3.php');
// Initialize getID3 engine
$getID3 = new getID3;
$DirectoryToScan = '/httpd/customers/virtual/mydomain.com/htdocs/morning_podcasts'; // change to whatever directory you want to scan
$dir = opendir($DirectoryToScan);
$xml_output = "<rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss/\">\n";
$xml_output .= "<channel>\n";
$xml_output .= "<title>Podasts</title>\n";
//$xml_output .= "<link>http://www.mydomain.com</link>\n";
while (($file = readdir($dir)) !== false) {
$FullFileName = realpath($DirectoryToScan.'/'.$file);
if (is_file($FullFileName)) {
set_time_limit(30);
$ThisFileInfo = $getID3->analyze($FullFileName);
getid3_lib::CopyTagsToComments($ThisFileInfo);
// output desired information in whatever format you want
$thetitle = ''.(!empty($ThisFileInfo['comments_html']['title']) ? implode('<BR>', $ThisFileInfo['comments_html']['title']) : ' ').'';
$thefile = ''.$ThisFileInfo['filename'].'';
//$lengtho = ''$ThisFileInfo['playtime_string']'';
$lengtho = ''.(!empty($ThisFileInfo['playtime_string']) ? $ThisFileInfo['playtime_string'] : ' ').'';
// output desired information in whatever format you want
$xml_output .= "<item>\n";
$xml_output .= "<title>$thetitle</title>\n";
$xml_output .= "<link>http://www.keenerocks.com</link>\n";
$xml_output .= "<description>PODCAST</description>\n";
//$xml_output .= "<pubDate>Sat, 07 Sep 2002 09:42:31 GMT</pubDate>\n";
$xml_output .= "<media:content url=\"http://www.mydomain.com/morning_podcasts/$thefile\" duration=\"$lengtho\"/>\n";
$xml_output .= "<media:thumbnail url=\"http://www.mydomain.com/images/morning_show.jpg\" />\n";
$xml_output .= "</item>\n";
}
}
$xml_output .= "</channel>\n";
$xml_output .= "</rss>\n";
$file_handle = fopen('rss.xml','w');
fwrite($file_handle,$xml_output);
fclose($file_handle);
echo $xml_output;
?>