Jump to content

output dir to xml


tryingtolearn

Recommended Posts

I have a function which is listing my directories w/ files (Images) in them.

<?php
function sortDirectory($path = 'images') {  
  $ignore = array('.', '..', 'index.php');
  $folder = array();
  $dh = @opendir($path);
  while (false !== ( $file = readdir($dh) )) {
if (!in_array($file, $ignore)) {
  if (is_dir("$path/$file")) {
	$folder[$file] = sortDirectory("$path/$file");
  } else {
	$folder[$file] = "$path/$file";
  }
}
  }
  closedir($dh);
  ksort($folder);
  return $folder;
}

function getDirectory($folder = array(),$level = 0) {
// Set which extensions should be approved in the XML file
  $extensions = array(  'jpg', 'JPG',  'png', 'PNG',  'gif', 'GIF',  'bmp', 'BMP');
  $spaces = str_repeat(' ', ( $level * 4));
  foreach($folder as $file=>$path) {
if (is_array($path)) {
  echo "<strong>$spaces $file</strong><br />";
  getDirectory($path, $level+1);
}
else {
if ( in_array( substr($file, -3), $extensions ) ){
  echo "$spaces <a href=\"$path\">$file</a><br />";
  }
}
  }
}

getDirectory(sortDirectory());

?>

Im trying to get it to write an xml file in this fashion

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<dir1>
    <pic>
        <image>file1.jpg</image>        
    </pic>
    <pic>
        <image>file2.jpg</image>        
    </pic>    
</dir1>

<dir2>
    <pic>
        <image>file1.jpg</image>        
    </pic>
    <pic>
        <image>file2.jpg</image>        
    </pic>    
</dir2>

but I cannot seem to get a grasp on this simplexml for more than 1 directory - any help appreciated.?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.