douzen1880 2014-10-22 21:42
浏览 13

使用readdir omit filetype创建xml

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);
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 谁有RH342练习环境
    • ¥15 STM32F407 DMA中断问题
    • ¥15 uniapp连接阿里云无法发布消息和订阅
    • ¥25 麦当劳点餐系统代码纠错
    • ¥15 轮班监督委员会问题。
    • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
    • ¥20 关于变压器的具体案例分析
    • ¥15 生成的QRCode圖片加上下載按鈕
    • ¥15 板材切割优化算法,数学建模,python,lingo
    • ¥15 科来模拟ARP欺骗困惑求解