Donnie Darko Posted May 20, 2009 Share Posted May 20, 2009 I'm trying to code a simple CMS of my own based on XML for my senior project. I'm halfway done. I'm currently stuck on this one function where I need to open and read multiple folders, then read all the files in them so I can put them in my domxml_open_file() function like domxml_open_file($file) - I have different folders such as Housing_Stuff, College_Stuff etc. and .xml files named after their IDs in them such as 1.xml, 2.xml. I tried various methods to read multiple folders and stuff but can't get it to work and it is frustrating me to an extreme. Here are the codes: session_start(); function printNow($array){ if(count($array) <= 1){ for ($i = 0; $i<count($array); $i++){ $node = $array[$i]; $value = $node->get_content(); } return $value; } } function folderlist(){ $nowDir = './admin/'; $ignoreDir[] = '.'; $ignoreDir[] = '..'; $ignoreDir[] = 'xmldata'; $ignoreDir[] = 'images'; $ignoreDir[] = 'backup'; $ignoreDir[] = 'jscripts'; if (is_dir($nowDir)){ if ($dh = opendir($nowDir)){ while (($folder = readdir($dh)) !== false){ if (!(array_search($folder,$ignoreDir) > -1)){ if (filetype($nowDir . $folder) == "dir"){ $dirList[$nowDir . $folder]['name'] = $folder; } } } closedir($dh); } } return($dirList); } $folders = folderlist(); foreach ($folders as $folder){ $folderName = $folder['name']; } $read = opendir("./admin/$folderName/"); $fileCount = 0; while ($file = readdir($read) and $fileCount < 5){ if (eregi("^\\.\\.?$", $file)) { continue; } $open = "./admin/$folderName/".$file; $xml = domxml_open_file($open); // Pull the stuff we need and build the links $identify = $xml->root(); $id = $identify->get_attribute("id"); $d0cument = $xml->root(); $hl_array = d0cument->get_elements_by_tagname("headline"); $hline = printNow($hl_array); $d0cument = $xml->root(); $sd_array = $d0cument->get_elements_by_tagname("summ"); $sd = printNow($sd_array); $d0cument = $xml->root(); $aa_array = $d0cument->get_elements_by_tagname("author"); $aa = printNow($aa_array); $d0cument = $xml->root(); $ada_array = $d0cument->get_elements_by_tagname("date"); $ada = printNow($ada_array); $fileCount++; } <center><table width="625" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="25" background="<?echo$sitetheme;?>/images/orta.gif"><b><h3><? echo $lang['article'];?></b></h3></font> </td> </tr> </table> </center> <? echo '<div id="div">'; echo '<ul id="sidebarnav_Main">'; echo "<li><a href=article.php?id=".$id.">".$ada." > ".$folderName." > ".$hline."</a></li></ul><div>"; ?> The output of this is: > College_Stuff > with the link not having any of the properties I want it to have such as $id etc. And the $folderName function apparently just gets the name of one folder, when there are 2 other folders it should be taking the names of. When I change the $folderName with an actual folder name such as Housing_Stuff for these 2 lines: $read = opendir("./admin/$folderName/"); $open = "./admin/$folderName/".$file; The functions work fine and the script pulls the properties of the file but it only pulls 2.xml, and there is another .xml file in that folder named 1-1242743475.xml. I'm totally stuck and in need of help. Hopefully I was able to explain the problem well enough. Link to comment https://forums.phpfreaks.com/topic/158919-openread-multiple-subfolders-and-read-all-files-in-them-problem-php-domxml/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.