i have been stuck for days and cant seem to figure this out.
I am reading a dir and taking those filenames and creating a xml file.
issue is only want to use video files or image files. the xml is then read into a table with pagination. so i only want files i will use, not .txt, .php or other .xml in that directory.
here is code i have now:
if ($handle = opendir('recordings')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$loadThisUrl = "recordings/recordings.xml";
$xmldoc = new DomDocument( '1.0' );
$xmldoc->preserveWhiteSpace = false;
$xmldoc->formatOutput = true;
if( $xml = file_get_contents( $loadThisUrl ) ) {
$xmldoc->loadXML( $xml, LIBXML_NOBLANKS );
// find the channels tag
$root = $xmldoc->getElementsByTagName('channels')->item(0);
// create the <channel> tag
$channel= $xmldoc->createElement('channel');
// add ID to <channel> tag
$id = $xmldoc->getElementsByTagName('channel')->length;
$idAttribute = $xmldoc->createAttribute("id");
$idAttribute->value = $id;
// add name to <channel> tag
$nameAttribute = $xmldoc->createAttribute("name");
$nameAttribute->value = $entry;
// add url to <channel> tag
$urlAttribute = $xmldoc->createAttribute("url");
$urlAttribute->value = $entry;
// add category to <channel> tag
$categoryAttribute = $xmldoc->createAttribute("category");
$categoryAttribute->value = "recordings";
// add quality to <channel> tag
$qualityAttribute = $xmldoc->createAttribute("quality");
$qualityAttribute->value = "best";
$channel->appendChild($idAttribute);
$channel->appendChild($urlAttribute);
$channel->appendChild($nameAttribute);
$channel->appendChild($categoryAttribute);
$channel->appendChild($qualityAttribute);
// add the product tag before the first element in the <headercontent> tag
$root->insertBefore( $channel, $root->firstChild );
$xmldoc->save($loadThisUrl);
}
}
}
closedir($handle);
}