Code: Select all
<?php
header("Content-type: text/xml");
/*
echo "<?xml version='1.0' encoding='utf-8'?>" ;
*/
$xmlFile = "<?xml version='1.0' encoding='utf-8'?>";
//echo '<mainFolder>';
$xmlFile .= '<mainFolder>';
getDirectory('/Volumes/WEB/area/uploadtest');
function getDirectory( $path = "getcwd()")
{
global $xmlFile;
$ignore = array( 'cgi-bin', '.', '..','.svn','.DS_Store', 'folders.xml' );
// Directories to ignore when listing output.
$dh = @opendir( $path );
// Open the directory to the handle $dh
while( false !== ( $file = readdir( $dh ) ) )
{
// Loop through the directory
if( !in_array( $file, $ignore ) )
{
// Check that this file is not to be ignored
if(is_dir( "$path/$file" ) )
{
// Its a directory, so we need to keep reading down...
$folder = $file;
//echo "<folder folderName='$folder'>";
$xmlFile .= "<folder folderName='$folder'>";
getDirectory( "$path/$file");
//echo "</folder>";
$xmlFile .= "</folder>";
// Re-call this same function but on a new directory.
// this is what makes function recursive.
}
else
{
$location = "$path/$file";
$type = pathinfo($location, PATHINFO_EXTENSION);
//echo "<file filename='$file' location = '$location'/>";
$xmlFile .= "<file filename='$file' location = '$location' type='$type' />";
// Just print out the filename
}
}
}
closedir( $dh );
// Close the directory handle
}
//echo '</mainFolder>';
$xmlFile .= '</mainFolder>';
echo $xmlFile;
$xmlFileName = getcwd()."/folders.xml";
//echo $xmlFileName;
fopen($xmlFileName, "w+");
fwrite($xmlFileName,$xmlFile);
fclose($xmlFileName);
?>