/*
what i'm trying to do is read the files and folders in the directory and
output them into an xml document - when i try to find the size of the file i
get an error - can someone please tell me why this is

thanks

mike
*/

// SCRIPT [dir.php]
<?
function folder2XML(){
    $fp = opendir('.');                                // make $fp hold the
current directory
    while (false !== ($file = readdir($fp))) {         // for each file or
folder in the directory...
        if ($file != "." && $file != "..") {           // if it's not the
current folder or the parent folder...
            if (is_dir($file)) {                       // if it's a
folder...
                echo "<folder name='$file'>";        // open the folder tag and
put the folder name in it
                chdir($file);                          // change to that
directory
                folder2XML();                          // make our recursive
call to display this directory too.
                chdir("../");                          // change back to
previous directory
                echo "</folder>";                      // close the folder
tag
            } else {                                   // if it's a file...
                // the error is bieng caused here
                $size = int filesize($file)
                echo "<file name='$file' size='$size' />";
                // if you comment out the above 2 lines and include the below instead 
it
works
                // echo "<file name='$file' />";
            }
        }
    }
    closedir($fp);                                     // close the open
directory
}
echo("<?xml version='1.0' ?>");

?><folder name='/'><?                                  // Open the root
element's tag (it's the root folder, of course)
folder2XML();                                          // Display the folder
as XML (and all sub folders!)
?></folder><?                                          // close the root element
?>
// END


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to